A HA application cache synchronization method, device, equipment and medium
By creating a cache for each node in the HA application and using the Socket protocol to synchronize cached events, the problem of difficult memory data sharing between master and slave nodes is solved, achieving high availability and ease of use.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-25
- Publication Date
- 2026-04-10
AI Technical Summary
In HA mode, it is difficult to share memory data between master and slave nodes. Existing technologies use caching middleware such as Redis, which leads to high availability issues and causes inconvenience to small applications.
A cache is created for each node, and a channel is established between the master and slave nodes using the Socket protocol to monitor and synchronize cache events. Components such as configuration center, resource manager, data synchronization manager and communication gateway are used to realize cache synchronization.
It achieves high availability without additional deployment, provides easy-to-use and simple cache synchronization, and is suitable for various application languages.
Smart Images

Figure CN116647571B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and in particular to a HA application cache synchronization method, device, equipment and medium. BACKGROUND
[0002] In today's big data explosion, the network architecture of the Internet has been developing in the direction of distribution and high concurrency. In order to ensure the high availability and robustness of the service, small service applications often adopt a dual-machine cluster system (Highly Available, referred to as HA) mode. The memory data sharing between master and slave nodes in the HA mode is a common problem.
[0003] At present, the main solution to this problem in the industry is to use a distributed cache middleware Redis (high-performance key-value cache middleware). The high-performance key-value cache middleware Reids can certainly solve this problem, but part of the small application software is not large in size, and after introducing Redis, the high availability of Redis needs to be considered, which is a typical problem that introduces a new problem to solve the problem, bringing great inconvenience to users. SUMMARY
[0004] Therefore, it is necessary to provide a HA application cache synchronization method, device, equipment and medium for the above technical problems.
[0005] According to a first aspect of the present application, a HA application cache synchronization method is provided, the method comprising:
[0006] a cache is created for each node of the HA application, wherein the cache is used to monitor cache events of changes in the cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule;
[0007] the master node obtains the cache address of the standby node by using a HA communication mechanism;
[0008] a Socket channel is established between the cache of each standby node and the cache of the master node based on the cache address and the Socket protocol;
[0009] in response to the cache event monitored by the cache of a certain standby node, the cache synchronization event message body is sent to the cache of the master node through the Socket channel, and the cache synchronization event message body is synchronized to the cache of other standby nodes by using the cache of the master node for processing;
[0010] in response to the cache event monitored by the cache of the master node, the cache synchronization event message body is synchronized to the cache of each standby node by using the cache of the master node for processing.
[0011] In some embodiments, each cache includes a configuration center, a resource manager, a data synchronization manager, a life cycle manager, and a communication gateway.
[0012] The configuration center is configured to manage the cache address corresponding to the node, the timeout time of the node, and the full synchronization interval.
[0013] The resource manager is configured to perform the operations of adding, deleting, modifying, and querying the cache data, and writing and reading the persistent resources.
[0014] The data synchronization manager is configured to generate a cache synchronization event message body based on the changes in the local cache or receive and process the cache synchronization event message body sent by other caches.
[0015] The life cycle manager is configured to listen to and maintain the life cycle of the local cache resources.
[0016] The communication gateway is configured to communicate with other caches.
[0017] In some embodiments, the preset rules include:
[0018] In response to a change in a cache resource in the resource manager, the data synchronization manager performs the following operations:
[0019] A unique event identification field is generated for the current cache resource change.
[0020] A trigger time field is generated according to the time point of the current cache resource change.
[0021] A trigger node field is generated according to the node corresponding to the cache that triggered the current cache resource change.
[0022] A period field is generated according to the life cycle of the cache data of the current cache resource change.
[0023] A cache key field is generated according to the cache key of the current cache resource change.
[0024] A cache data field is generated according to the data of the current cache resource change.
[0025] The event identification field, the trigger time field, the trigger node field, the period field, the cache key field, and the cache data field are spliced to generate a cache synchronization event message body.
[0026] In some embodiments, the cache follows the following rules to process the cache synchronization event message body:
[0027] In response to the data synchronization manager receiving the cache synchronization event message body, the following checks are performed in sequence:
[0028] determining whether the local cache key exists;
[0029] in response to the local cache key existing, determining whether the local cache resource change time is later than the trigger time field in the received cache synchronization event message body;
[0030] in response to the local cache resource change time being later than the trigger time field in the received cache synchronization event message body or the local cache key not existing, updating the local data;
[0031] in response to the local data being updated, determining whether the local node is the master node;
[0032] in response to the local node being the master node or the local cache resource change time being earlier than the trigger time field in the received cache synchronization event message body, triggering the cache synchronization of the local node and other nodes.
[0033] In some embodiments, the method further comprises:
[0034] in response to a preset situation occurring, triggering a full-amount synchronization event by the data synchronization manager in the cache corresponding to the master node, wherein the full-amount synchronization event is used to trigger the cache synchronization event by the cache corresponding to the master node in turn and circularly for all local cache data, and synchronize all data to the cache corresponding to the standby node, and the preset situation includes the master node periodic synchronization, the master node initial reading of the persistent data, a new standby node accessing, and the master node and the standby node switching.
[0035] In some embodiments, the method further comprises:
[0036] monitoring the life cycle of the local cache data by using the life cycle manager of each cache;
[0037] in response to the cache time of a certain cache data reaching the preset time, notifying the resource manager to delete the certain cache data and triggering the cache synchronization event by the life cycle manager.
[0038] In some embodiments, the method further comprises:
[0039] in response to the full-amount synchronization event being triggered, persisting the cache data to the local file system by the resource manager in the cache corresponding to each node;
[0040] in response to the master node switching, modifying the local cache type by the communication gateway after receiving the node switching event, and the cache following the node switching completion;
[0041] in response to the master node going down, the cache corresponding to the health state standby node performing the following operations:
[0042] Setting the buffer corresponding to the master node to be down and disconnecting the Socket channel in the communication gateway corresponding to the buffer of the standby node;
[0043] The communication gateway of the health status standby node periodically polls the node and other standby nodes to determine whether a standby node takes over the original master node to become a new master node;
[0044] In response to the occurrence of a new master node, the buffer of the new master node and the master-slave communication channel of other standby nodes are re-established, and a full synchronization event is triggered;
[0045] In response to the occurrence of all nodes being down, the data persisted locally is re-read into the cache after the service is restarted.
[0046] According to a second aspect of the present application, a HA application cache synchronization device is provided, and the device comprises:
[0047] A cache creation module is configured to create a buffer for each node of the HA application, wherein the buffer is used to monitor a cache event of a change in the cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule;
[0048] An acquisition module is configured to acquire the buffer address of the standby node by the master node using a HA communication mechanism;
[0049] A Socket channel establishment module is configured to establish a Socket channel between the buffer corresponding to each standby node and the buffer corresponding to the master node based on the buffer address and a Socket protocol;
[0050] A first processing module is configured to, in response to the buffer corresponding to a certain standby node monitoring a cache event, send the cache synchronization event message body to the buffer corresponding to the master node through the Socket channel, and synchronize the cache synchronization event message body to the buffer corresponding to other standby nodes through the buffer of the master node for processing;
[0051] A second processing module is configured to, in response to the buffer corresponding to the master node monitoring a cache event, synchronize the cache synchronization event message body to the buffer corresponding to each standby node through the buffer of the master node for processing.
[0052] According to a third aspect of the present application, an electronic device is also provided, and the electronic device comprises:
[0053] At least one processor; and
[0054] The memory stores a computer program which can run on the processor, and the processor executes the program to execute the HA application cache synchronization method.
[0055] According to a fourth aspect of the present application, a computer readable storage medium is also provided, which stores a computer program, and the computer program is executed by a processor to execute the HA application cache synchronization method.
[0056] The HA application cache synchronization method can realize high availability without additional deployment, and the Socket protocol is used as the communication mechanism, so that the cache synchronization has no limitation on the application language, and the service provides easy and simple cache synchronization capability.
[0057] In addition, the present application also provides an HA application cache synchronization device, an electronic device and a computer readable storage medium, which can also realize the above technical effects, and details are not described herein. BRIEF DESCRIPTION OF DRAWINGS
[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other embodiments can be obtained without creative labor on the basis of these drawings.
[0059] Figure 1 A flow chart of an HA application cache synchronization method provided for an embodiment of the present application;
[0060] Figure 2 A cache communication mechanism schematic diagram provided for another embodiment of the present application;
[0061] Figure 3 A cache internal service architecture schematic diagram provided for an embodiment of the present application;
[0062] Figure 4 A processing mechanism schematic diagram in the cache of an HA application service initial start provided for an embodiment of the present application;
[0063] Figure 5 A structure schematic diagram of a cache synchronization event message body provided for an embodiment of the present application;
[0064] Figure 6 A cache event routing rule schematic diagram provided for an embodiment of the present application;
[0065] Figure 7 A cache event flow process schematic diagram of a data synchronization manager provided for an embodiment of the present application;
[0066] Figure 8 The structure diagram of the HA application cache synchronization device provided for another embodiment of the present application is shown in the figure;
[0067] Figure 9 The internal structure diagram of the electronic device in another embodiment of the present application is shown in the figure;
[0068] Figure 10 The structure diagram of the computer readable storage medium in another embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0069] In order to make the purpose, technical solutions and advantages of the present application clearer and more apparent, the embodiments of the present application are further described in detail below with reference to the accompanying drawings.
[0070] It should be noted that all the expressions of "first" and "second" in the embodiments of the present application are used to distinguish two same name non-identical entities or non-identical parameters, and it can be seen that "first" and "second" are only for the convenience of description, and should not be understood as a limitation of the embodiments of the present application, and the subsequent embodiments will not be described one by one.
[0071] In one embodiment, referring to Figure 1 The present application provides a HA application cache synchronization method 100, and specifically, the method comprises the following steps:
[0072] Step 101, a cache is respectively created for each node of the HA application, wherein the cache is used to monitor the cache event of the change of the cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule;
[0073] In the embodiment, HA is the abbreviation of Highly Available, which is the abbreviation of dual-computer cluster system, and the improved availability cluster is an effective solution to ensure business continuity, generally has two or more nodes, and is divided into a master node (also known as an active node) and a standby node.
[0074] Step 102, the cache address of the standby node is obtained by the master node using the HA communication mechanism;
[0075] Step 103, a Socket channel is established between the cache corresponding to each standby node and the cache corresponding to the master node based on the cache address and the Socket protocol;
[0076] In the embodiment, Socket is a long-link communication protocol based on the TCP / IP communication protocol, and the communication is generally divided into a server and a client, the cache corresponding to the master node is the server, and the cache corresponding to the standby node is the client.
[0077] Step 104, in response to a certain backup node corresponding to the cache monitor to cache event, then through the Socket channel to the main node corresponding to the cache buffer, and use the main node of the cache buffer to synchronize the cache synchronization event message body to other backup node corresponding to the cache buffer for processing;
[0078] Step 105, in response to the main node corresponding to the cache monitor to cache event, then use the main node of the cache buffer to synchronize the cache synchronization event message body to each backup node corresponding to the cache buffer for processing.
[0079] The above-mentioned HA application cache synchronization method, through the following node to start the cache, realizes the high availability without additional deployment, and uses the Socket protocol as the communication mechanism to make the cache synchronization unrestricted to the application language, and provides easy-to-use, simple cache synchronization ability for the service.
[0080] In some embodiments, each cache includes a configuration center, a resource manager, a data synchronization manager, a life cycle manager and a communication gateway;
[0081] The configuration center is used to manage the cache address corresponding to the node, the timeout time of the node, and the full-amount synchronization interval;
[0082] The resource manager is used for the add, delete, modify and query of cache data, and the writing and reading of persistent resources;
[0083] The data synchronization manager is used to generate a cache synchronization event message body based on local cache changes or receive and process cache synchronization event message bodies sent by other caches;
[0084] The life cycle manager is used to listen to and maintain the life cycle of local cache resources;
[0085] The communication gateway is used for communication with other caches.
[0086] In some embodiments, the preset rules include:
[0087] In response to a change in a certain cache resource in the resource manager, the data synchronization manager performs the following operations:
[0088] Generate a unique event identification field for this cache resource change;
[0089] Generate a trigger time field according to the time point of this cache resource change;
[0090] Generate a trigger node field according to the node corresponding to the cache that triggered this cache resource change;
[0091] The cache data life cycle generation period field is generated according to the cache resource change this time;
[0092] The cache key field is generated according to the cache key change this time;
[0093] The cache data field is generated according to the data change this time;
[0094] The event identification field, the trigger time field, the trigger node field, the period field, the cache key field and the cache data field are spliced to generate a cache synchronization event message body.
[0095] In some embodiments, the cache complies with the following rules to process the cache synchronization event message body:
[0096] In response to the data synchronization manager receiving the cache synchronization event message body, the following checks are sequentially performed:
[0097] It is judged whether the local cache key exists or not;
[0098] In response to the local cache key existing, it is judged whether the local cache resource change time is later than the trigger time field in the received cache synchronization event message body or not;
[0099] In response to the local cache resource change time being later than the trigger time field in the received cache synchronization event message body or the local cache key not existing, the local data is updated;
[0100] In response to the local data being updated, it is judged whether the current node is the master node or not;
[0101] In response to the current node being the master node or the local cache resource change time being earlier than the trigger time field in the received cache synchronization event message body, the cache of the current node and other nodes is triggered to cache synchronization.
[0102] In some embodiments, the method further comprises:
[0103] In response to a preset situation occurring, the data synchronization manager in the cache corresponding to the master node triggers a full-amount synchronization event once, wherein the full-amount synchronization event is used for the cache corresponding to the master node to sequentially cycle all local cache data to trigger a cache synchronization event, and synchronizes all data to the cache corresponding to the backup node, wherein the preset situation includes master node periodic synchronization, master node initial reading of persistent data, new backup node access, and master node and backup node switching.
[0104] In some embodiments, the method further comprises:
[0105] monitoring the life cycle in the local cache data by using the life cycle manager of each cache;
[0106] In response to the cache data reaching its preset time, the life cycle manager notifies the resource manager to delete the cache data and triggers a cache synchronization event.
[0107] In some embodiments, the method further comprises:
[0108] In response to the full-amount synchronization event being triggered, the resource manager in the cache corresponding to each node persists the cache data to the local file system;
[0109] In response to the master node switching, the communication gateway modifies the type of the local cache after receiving the node switching event, and the cache follows the node switching to complete;
[0110] In response to the master node being down, the cache corresponding to the health status standby node performs the following operations:
[0111] The cache corresponding to the master node is set to be down, and the Socket channel in the communication gateway corresponding to the cache of the standby node is disconnected;
[0112] The communication gateway of the health status standby node periodically polls the node and other standby nodes to determine whether a standby node takes over the original master node to become a new master node;
[0113] In response to a new master node appearing, the cache of the new master node and the master-slave communication channel of other standby nodes are re-established, and a full-amount synchronization event is triggered;
[0114] In response to all nodes being down, the data persisted in the local is re-read into the cache after the service is restarted.
[0115] In another embodiment, in order to facilitate understanding of the scheme of the present application, please refer to Figure 2 It is assumed that a HA application includes three nodes, namely the master node A and the standby nodes B and C. The cache corresponding to the master node is cache A, and the caches corresponding to the standby nodes B and C are cache B and cache C, respectively. The present embodiment provides a HA application cache synchronization method to solve the problem that the HA application does not want to introduce a third-party cache middleware and the difficulty of memory cache synchronization. The cache is created following the HA node, the cache of the master node is used as the Server end, and other standby nodes are used as the Client end to use Socket for data synchronization. At the same time, a cache synchronization mechanism and an exception recovery mechanism are established to provide an easy-to-use and simple cache synchronization capability for services. The specific implementation process of the method of the present application will be described in detail based on the above scenario:
[0116] Cache communication mechanism: as follows Figure 2 The cache follows the relationship of the HA application node, and the cache synchronization mode between the nodes, the cache follows the HA node start, stop, and itself has high availability characteristics. By using the HA communication mechanism, the addresses of other caches are obtained. The cache of the master node establishes a Socket server to receive the connection of the cache of other standby nodes, thereby realizing network communication.
[0117] Cache architecture: please refer to Figure 3 The functions of the related components in the cache are as follows:
[0118] (1) Configuration center: responsible for managing all configuration information of the cache, including but not limited to: HA node service address, node timeout time, full synchronization interval, and other configuration information.
[0119] (2) Resource manager: maintains cache data and is responsible for adding, deleting, modifying, and querying cache data.
[0120] Maintain local persistent resource data, responsible for writing and reading persistent resources.
[0121] (3) Data synchronization manager: responsible for local cache synchronization or receiving external cache, and processing cache synchronization events.
[0122] (4) Life cycle manager: responsible for listening and maintaining the life cycle of local cache resources.
[0123] (5) Communication gateway: responsible for external network communication.
[0124] Please refer to Figure 4 After the cache is initially started, the internal processing mechanism is as follows: first, the configuration center reads the configuration information; then the resource manager reads the local persistent file, removes the expired cache data, and loads other data into the cache resource; at the same time, the data synchronization manager continuously monitors the local cache resource data and starts the data statistics mechanism; the life cycle manager will monitor the local cache resource data and start the life cycle management mechanism; finally, the communication gateway initializes the communication channel according to the node type. The cache is started.
[0125] The following will explain in detail the mechanism followed by each cache to realize synchronization:
[0126] I. Cache incremental synchronization mechanism
[0127] When a cache resource in the resource manager changes, the data synchronization manager is notified to trigger the cache synchronization event.
[0128] Please refer to Figure 5 and Figure 6As shown, the cache event routing rules are as follows: if it is a standby node trigger, the event message body will be sent to the master node through the Socket channel, and the master node will be synchronized to other standby nodes. If it is a master node trigger, the event will be sent to other standby nodes of the trigger node.
[0129] Please refer to Figure 7 As shown, the cache event processing rules are as follows: After the data synchronization manager receives the data synchronization request, it will perform the following checks in turn: First, check if the local cache key exists, if so, then check if the local event time is later than the synchronization data, if so or the local cache key does not exist, then perform update; Then judge whether the local node is an active node (i.e. master node), if so or the local event time is earlier than the synchronization data, then trigger cache synchronization.
[0130] II. Cache full synchronization mechanism
[0131] When certain conditions are met, the data synchronization manager of the master node will trigger a full synchronization event. After the full synchronization trigger, the master node will trigger the cache synchronization event in turn for all local cache data, and synchronize all data to the standby node. Specifically, the following scenarios will trigger the full synchronization event:
[0132] (1) Master node regular synchronization: For example, you can set it to synchronize every 15 minutes, and the master node will trigger the data synchronization event.
[0133] (2) Master node first reads persistent data: Generally occurs when the application is first started.
[0134] (3) New standby node access: Generally occurs when a new standby node is created or a standby node is restarted.
[0135] (4) Master node changes: Generally occurs when the master and standby nodes are switched.
[0136] III. Abnormal scenario compensation mechanism
[0137] (1) Local persistence: Whenever full cache synchronization is triggered, the resource manager of each node will persist the cache data to the local file system to prevent data loss due to unexpected service interruption. When the service is first started, it will read the local persistent file and convert the file data content into cache data.
[0138] (2) Node exception handling mechanism
[0139] HA service service exception, according to the actual situation, it is divided into three kinds:
[0140] The first scenario involves an active node switchover, where the standby node is promoted to active, and the original active node is downgraded to standby. In this scenario, after receiving the node switchover event, the communication gateway modifies the local buffer type, and the buffer follows the service node switchover.
[0141] The second scenario involves the active node failing, and the standby node being promoted to active. In this scenario, the healthy standby cache will perform the following operations: if the active cache fails, the socket channel within the standby cache's communication gateway will be disconnected; the communication gateway will periodically poll this node and other standby nodes to see if any standby node has taken over the active node; once a new active node appears, a new master-slave communication channel will be re-established, triggering a full cache synchronization.
[0142] The third scenario is when all nodes fail: After all nodes fail, the service restarts, which is equivalent to the initial startup of the service. The data persisted locally will be read back into memory.
[0143] The HA application cache synchronization method of this embodiment has at least the following beneficial technical effects:
[0144] First, establish a data synchronization mechanism to provide two scenarios: real-time incremental synchronization and periodic full synchronization, and provide cache synchronization capabilities.
[0145] Second, through local persistence mechanisms and abnormal node detection mechanisms, it provides uninterrupted service operation and recovery capabilities in abnormal scenarios.
[0146] Third, it starts up with the application node, and compared with other caching middleware, it has high availability capabilities without additional deployment.
[0147] In some embodiments, please refer to Figure 8 As shown, the present invention also provides an HA application cache synchronization device 200, the device comprising:
[0148] The cache creation module 201 is used to create a cache for each node of the HA application. The cache is used to monitor cache events of changes in cached data of the corresponding node and generate a cache synchronization event message body according to preset rules.
[0149] The acquisition module 202 is used by the master node to obtain the buffer address of the standby node using the HA communication mechanism;
[0150] Socket channel establishment module 203 is used to establish a Socket channel between the cache corresponding to each backup node and the cache corresponding to the master node based on the cache address and Socket protocol.
[0151] The first processing module 204 is configured to, in response to a cache event monitored by a cache corresponding to a certain standby node, send the cache synchronization event message body to the cache corresponding to the master node through a Socket channel, and synchronize the cache synchronization event message body to the caches corresponding to other standby nodes through the cache of the master node for processing.
[0152] The second processing module 205 is configured to, in response to a cache event monitored by a cache corresponding to the master node, synchronize the cache synchronization event message body to the caches corresponding to each standby node through the cache of the master node for processing.
[0153] The HA application cache synchronization device described above has high availability without additional deployment through the cache of the following node, and has easy-to-use and simple cache synchronization capability for services through the Socket protocol as the communication mechanism without limitation on the application language.
[0154] It should be noted that the specific limitations of the HA application cache synchronization device can be referred to the limitations of the HA application cache synchronization method described above, which will not be repeated here. Each module in the HA application cache synchronization device described above can be realized by software, hardware and their combinations in whole or in part. Each module described above can be embedded in or independent of the processor in the electronic device in hardware form, or can be stored in the memory in the electronic device in software form, so as to be called and executed by the processor to perform the operations corresponding to each module.
[0155] According to another aspect of the present application, an electronic device, which can be a server, is provided, and its internal structure is shown in Figure 9 The electronic device includes a processor, a memory, a network interface and a database connected through a system bus. The processor of the electronic device is configured to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium. The database of the electronic device is configured to store data. The network interface of the electronic device is configured to communicate with external terminals through network connection. The computer program is executed by the processor to implement the HA application cache synchronization method described above. Specifically, the method includes the following steps:
[0156] A cache is created for each node of the HA application, wherein the cache is configured to monitor a cache event of a change in the cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule;
[0157] The cache address of the standby node is obtained by the master node through the HA communication mechanism.
[0158] establishing a Socket channel between the cache corresponding to each standby node and the cache corresponding to the master node based on the cache address and the Socket protocol;
[0159] In response to the cache corresponding to a certain standby node monitoring a cache event, the cache synchronization event message body is sent to the cache corresponding to the master node through the Socket channel, and the cache synchronization event message body is synchronized to the caches corresponding to other standby nodes by the cache of the master node for processing.
[0160] In response to the cache corresponding to the master node monitoring a cache event, the cache synchronization event message body is synchronized to the caches corresponding to each standby node by the cache of the master node for processing.
[0161] According to still another aspect of the present application, a computer readable storage medium is provided, please refer to Figure 10 The computer program is executed by a processor to implement the HA application cache synchronization method described above, specifically including the following steps:
[0162] A cache is created for each node of the HA application, wherein the cache is used to monitor a cache event of a change in the cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule;
[0163] The cache address of the standby node is obtained by the master node using the HA communication mechanism;
[0164] establishing a Socket channel between the cache corresponding to each standby node and the cache corresponding to the master node based on the cache address and the Socket protocol;
[0165] In response to the cache corresponding to a certain standby node monitoring a cache event, the cache synchronization event message body is sent to the cache corresponding to the master node through the Socket channel, and the cache synchronization event message body is synchronized to the caches corresponding to other standby nodes by the cache of the master node for processing.
[0166] In response to the cache corresponding to the master node monitoring a cache event, the cache synchronization event message body is synchronized to the caches corresponding to each standby node by the cache of the master node for processing.
[0167] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, storage, databases, or other media in the embodiments provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0168] The technical features of the above embodiments can be combined in any way. In order to make the description simple, not all possible combinations of the technical features in the above embodiments are described, but as long as the combinations of the technical features do not exist, they should be considered as the scope of the present application.
[0169] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, some modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of the patent of the present application should be subject to the appended claims.
Claims
1. A method for HA application cache synchronization, the method comprising: The method comprises: a cache is respectively created for each node of an HA application, wherein the cache is used to monitor cache events of changes in cache data of the corresponding node and generate a cache synchronization event message body according to a preset rule, and the cache is configured to be started following the node of the corresponding HA application; a backup node cache address is obtained by a master node using an HA communication mechanism; a Socket channel is established between the cache of each backup node and the cache of the master node based on the cache address and a Socket protocol; in response to the cache of a certain backup node monitoring a cache event, the cache synchronization event message body is sent to the cache of the master node through the Socket channel, and the cache synchronization event message body is synchronized to the caches of the other backup nodes by the cache of the master node for processing; in response to the cache of the master node monitoring a cache event, the cache synchronization event message body is synchronized to the caches of each backup node by the cache of the master node for processing.
2. The HA application cache synchronization method of claim 1, wherein, Each cache comprises a configuration center, a resource manager, a data synchronization manager, a life cycle manager and a communication gateway; the configuration center is used to manage the cache address of the node, the timeout time of the node and the full-amount synchronization interval; the resource manager is used for the addition, deletion, modification and query of cache data, and the writing and reading of persistent resources; the data synchronization manager is used to generate a cache synchronization event message body based on local cache changes or receive and process cache synchronization event message bodies sent by other caches; the life cycle manager is used to listen to and maintain the life cycle of local cache resources; the communication gateway is used for communication with other caches.
3. The HA application cache synchronization method of claim 2, wherein, The preset rule comprises: in response to a change in a certain cache resource in the resource manager, the data synchronization manager performs the following operations: generating a unique event identification field for this cache resource change; generating a trigger time field according to the time point of this cache resource change; generating a trigger node field according to the node corresponding to the cache that triggered this cache resource change; generating a period field according to the life cycle of the cache data of this cache resource change; generating a cache key field according to the cache key of this cache resource change; generating a cache data field according to the data of this cache resource change; splicing the event identification field, the trigger time field, the trigger node field, the period field, the cache key field and the cache data field to generate a cache synchronization event message body.
4. The HA application cache synchronization method of claim 3, wherein, The cache follows the following rules to process the cache synchronization event message body: in response to the data synchronization manager receiving a cache synchronization event message body, the following checks are performed in sequence: determining whether the local cache key exists; in response to the local cache key existing, determining whether the local cache resource change time is later than the trigger time field in the received cache synchronization event message body; in response to the local cache resource change time being later than the trigger time field in the received cache synchronization event message body or the local cache key not existing, updating the local data. In response to the local data being updated, it is determined whether the node is the master node; In response to the node being the master node or the local cache resource being changed earlier than the trigger time field in the received cache synchronization event message body, the cache of the node and other nodes is triggered to synchronize.
5. The HA application cache synchronization method according to any one of claims 2 to 4, characterized by, The method further includes: In response to a preset condition, the data synchronization manager in the cache corresponding to the master node triggers a full synchronization event, wherein the full synchronization event is used to trigger the cache corresponding to the master node to sequentially cycle through all local cache data to trigger a cache synchronization event, and synchronize all data to the cache corresponding to the standby node, and the preset condition includes periodic synchronization of the master node, initial reading of persistent data by the master node, access of a new standby node, and switching of the master node and the standby node.
6. The HA application cache synchronization method of claim 5, wherein, The method further includes: The life cycle of each cache is monitored by using the life cycle manager of each cache. In response to the cache time of a certain cache data reaching the preset time, the life cycle manager notifies the resource manager to delete the certain cache data and triggers a cache synchronization event.
7. The HA application cache synchronization method of claim 5, wherein, The method further includes: In response to the full synchronization event being triggered, the resource manager in the cache corresponding to each node persists the cache data to the local file system; In response to the master node switching, the local cache type is modified after the node switching event is received by the communication gateway, and the cache follows the node switching to complete; In response to the master node being down, the cache corresponding to the standby node performs the following operations: The cache corresponding to the master node is set to be down, and the Socket channel in the communication gateway of the cache corresponding to the standby node is disconnected; The communication gateway of the standby node periodically polls the node and other standby nodes to determine whether a standby node takes over the original master node to become a new master node; In response to a new master node appearing, the cache of the new master node and the master-slave communication channels of other standby nodes are re-established, and a full synchronization event is triggered; In response to all nodes being down, the data persisted in the local is re-read into the cache after the service is restarted.
8. An HA application cache synchronization apparatus, characterized by comprising: The device includes: A cache creation module, which is configured to create a cache for each node of an HA application, wherein the cache is configured to monitor cache events of the corresponding node and generate a cache synchronization event message body according to a preset rule, and the cache is configured to start following the node of the corresponding HA application; An acquisition module, which is configured to acquire the cache address of a standby node by a master node using an HA communication mechanism; A Socket channel establishment module, which is configured to establish a Socket channel between the cache corresponding to each standby node and the cache corresponding to the master node based on the cache address and a Socket protocol. The first processing module is configured to, in response to a cache event being monitored by a cache corresponding to a standby node, send the cache synchronization event message body to a cache corresponding to a master node through a Socket channel, and synchronize the cache synchronization event message body to caches corresponding to other standby nodes through the cache of the master node. The second processing module is configured to, in response to a cache event being monitored by a cache corresponding to a master node, synchronize the cache synchronization event message body to caches corresponding to each standby node through the cache of the master node.
9. An electronic device, comprising: The computer program is executed by the processor to perform the method of any one of claims 1-7. The computer program is executed by the processor to perform the method of any one of claims 1-7. 10. A computer-readable storage medium storing a computer program, the computer-readable storage medium comprising:
Citation Information
Patent Citations
Redis cache cross-center data processing method
CN114254046A
Cluster data synchronization method, apparatus and device, and computer readable storage medium
CN115550384A