Pre-switching method and device of main and standby nodes, equipment, medium and product
By monitoring the performance of database nodes to predict anomaly risks and performing lossless pre-switchover, the problem of low efficiency in traditional database switching is solved, enabling fast and lossless business switching and reducing the impact of failures on business.
Patent Information
- Application Number
- CN202511611074.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-05
- Publication Date
- 2026-02-10
AI Technical Summary
Traditional database switching carries the risk of passive response, has a long switching cycle, and can easily affect business operations. It is especially difficult to switch accurately and quickly in complex hardware failure environments, requiring human intervention and being inefficient.
By monitoring the performance of database nodes, abnormal risks can be predicted, and services can be seamlessly switched to backup nodes when pre-switch conditions are met. Pre-switch is achieved by caching front-end service requests and saving consistent snapshots, thus avoiding passive response.
Identify and address potential faults in advance to reduce the probability of fault occurrence, improve switching efficiency, minimize the impact on business operations, and ensure the stable operation of the database.
Smart Images

Figure CN121501546A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database operation and maintenance, and in particular to a pre-switch method and device for master and standby nodes, equipment, medium and product. BACKGROUND
[0002] In the field of database use, the traditional data switching has the risk of passive response. The database triggers the switching process after sensing the exception, and the switching occurs after a series of detection and alarm, the switching cycle is too long, and the business is easily affected.
[0003] Moreover, in the complex hardware exception environment, such as disk failure and network failure, it is difficult to accurately and quickly switch, and in this case, human intervention is often required, which is low in efficiency and easy to cause human disturbance. SUMMARY
[0004] The present application provides a pre-switch method and device for master and standby nodes, equipment, medium and product to improve the switching efficiency of the database in response to exceptions.
[0005] According to an aspect of the present application, a pre-switch method for master and standby nodes is provided, comprising:
[0006] predicting the exception risk of each master node according to the performance of the node;
[0007] if there is a master node with an exception risk meeting the pre-switch condition, the service of the master node is pre-switched to the corresponding standby node without loss.
[0008] According to another aspect of the present application, a pre-switch device for master and standby nodes is provided, comprising:
[0009] a risk prediction module for predicting the exception risk of each master node according to the performance of the node;
[0010] a lossless switching module for pre-switching the service of the master node to the corresponding standby node without loss if there is a master node with an exception risk meeting the pre-switch condition.
[0011] According to another aspect of the present application, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the pre-switch method for master and standby nodes according to any embodiment of the present application.
[0012] According to another aspect of the present application, there is provided an electronic device, comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the pre-switch method of the master and standby nodes according to any one of the embodiments of the present application.
[0013] According to another aspect of the present application, there is provided a computer readable storage medium storing computer instructions for enabling a processor to implement the pre-switch method of the master and standby nodes according to any one of the embodiments of the present application when executed by the processor.
[0014] The embodiments of the present application make risk identification and response in advance, pre-switch for possible faults and abnormalities; meanwhile, the pre-switch can realize lossless switching through buffering front-end service requests, saving a consistent snapshot before pre-switch, and the like, so as to avoid passive response when a real fault occurs, reduce the probability of fault occurrence and the impact on services when a real fault occurs, and improve switching efficiency.
[0015] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present application, nor to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0017] Figure 1 is a flowchart of a pre-switch method of master and standby nodes according to an embodiment of the present application;
[0018] Figure 2 is a flowchart of a pre-switch method of master and standby nodes according to another embodiment of the present application;
[0019] Figure 3 is a structural schematic diagram of a pre-switch device of master and standby nodes according to another embodiment of the present application;
[0020] Figure 4 is a structural schematic diagram of an electronic device for implementing the embodiments of the present application. DETAILED DESCRIPTION
[0021] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely with reference to the accompanying drawings of the embodiments of the present application. Obviously, the described embodiments are only a part but not all of the embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative work shall fall into the protection scope of the present application.
[0022] It should be noted that the terms "first", "second" and the like in the present application are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "comprise" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0023] Figure 1 A flowchart of a pre-switch method of a master and standby node according to an embodiment of the present application, which can be applicable to the case of dynamically adjusting the master and standby nodes according to their running states in the database. The method can be executed by a pre-switch device of the master and standby node, which can be realized in the form of hardware and / or software, and can be configured in an electronic device with corresponding data processing capability, such as a management system of the database. As shown in the figure, the method comprises: Figure 1
[0024] S110, predicting the abnormal risk of each master node according to the performance of the node.
[0025] S120, if there is a master node with abnormal risk meeting the pre-switch condition, switching the service of the master node to the corresponding standby node without loss.
[0026] Wherein, the abnormal risk includes low risk and high risk.
[0027] Specifically, the system monitors the performance of each (master / standby) node in the database in real time. For the master node, the abnormal risk is predicted according to the performance in all aspects. For the master node whose abnormal risk meets the pre-switching condition, the system determines the standby node of the master node from the database and completes the preparation work before pre-switching. After the preparation work is completed, the pre-switching process is initiated, which includes the switching of the master node and the standby node, and the operations of buffering the front-end business request and saving the snapshot consistency before pre-switching during the switching process to ensure lossless switching. After the pre-switching is completed, the original master node becomes the new standby node, and the original standby node becomes the new master node. The front-end business request originally processed by the original master node is continued to be processed by the new master node. After the pre-switching is completed, the system focuses on monitoring the new master node to determine whether the abnormal problem is successfully solved by this pre-switching.
[0028] The embodiment of the application makes risk identification and response in advance, pre-switches the possible fault abnormality, and realizes lossless switching through buffering the front-end business request and saving the consistency snapshot before pre-switching, thereby avoiding passive response when the real fault occurs, reducing the probability of fault occurrence and the influence on the business when the real fault occurs, and improving the switching efficiency.
[0029] On the basis of the above-mentioned embodiment, the method further comprises:
[0030] If the abnormal risk of the new master node still meets the pre-switching condition within the observation time, a master-standby node abnormal report is generated according to the related information of the last lossless pre-switching;
[0031] The master-standby node abnormal report is pushed to the operation and maintenance personnel of the database.
[0032] Specifically, the new master node is monitored after pre-switching. If the abnormal risk of the new master node still meets the pre-switching condition within the observation time, it indicates that the abnormal risk cannot be solved by pre-switching and manual intervention of the operation and maintenance personnel is needed. According to the related information of the last lossless pre-switching, such as the switching time, the switching object and the switching reason, a master-standby node abnormal report is generated. The master-standby node abnormal report is pushed to the operation and maintenance personnel for manual analysis of the abnormal reason and solution.
[0033] Figure 2 A flowchart of a pre-switching method of a master-standby node is provided for another embodiment of the application, which is optimized and improved on the basis of the above-mentioned embodiment. As shown in FIG. 8, the method comprises: Figure 2
[0034] S210, for each primary node in the database, determine performance of the primary node in each detection index; if there is a detection index whose performance is lower than the corresponding performance threshold, determine that the abnormal risk of the primary node is high risk.
[0035] The detection index includes memory, disk and network.
[0036] Specifically, for each primary node in the database, analyze its performance from the following detection indexes respectively, and determine its abnormal risk:
[0037] 1. Network: check the network performance of the primary node by ping and iperf. If the network packet loss rate of the primary node reaches a specific network threshold within a range of several minutes or a certain time range (for example, one day), it means that the network has obvious abnormalities, and the abnormal risk of the primary node is determined to be high risk.
[0038] 2. Disk: detect the disk performance of the primary node by iostat, dstat and other commands. If the iowait of the disk is too large to exceed the normal threshold during the disk idle period, and the disk error log and bad block related information are monitored by dmesg, badblocks and other commands, if it is detected that it exceeds a specific threshold, it is considered that the disk has obvious abnormalities, and the abnormal risk of the primary node is determined to be high risk.
[0039] 3. Memory: quickly check whether the system physical memory and swap space are abnormal by free command and other forms, monitor memory pressure and growth trend by vmstat, and detect whether there is a risk of memory leakage by slabtop, valgrind and other methods. If there is a case of excessive memory pressure exceeding the threshold or memory leakage, it means that the CPU has obvious abnormalities, and the abnormal risk of the primary node is determined to be high risk.
[0040] S220, if there is a primary node whose abnormal risk meets the pre-switching condition, cache the front-end business handled by the primary node, and save the consistency snapshot of the primary node before pre-switching.
[0041] S230, pause the database write channel, and switch the primary and standby identities of the primary node and the corresponding standby node.
[0042] S240, restore the consistency snapshot before pre-switching; replay the cached front-end business request to the new primary node, and reset the database write channel.
[0043] Specifically, frontend business requests are cached in memory or a distributed cache (such as Redis) to ensure no requests are lost. Before switching, a snapshot of the primary node's current state is saved, including transaction logs, lock states, and cache states. Write operations on the primary node are paused to ensure data consistency, while read operations are allowed to continue.
[0044] Switch the application connection from the primary node to the standby node, dynamically updating the data source configuration via a configuration center (such as Nacos). Ensure the standby node has synchronized all incomplete transactions with the primary node to maintain data consistency. The standby node starts the service, receives and processes database requests, and switches its state to "primary," while the primary node switches its state to "standby." Restore the primary node to its consistent snapshot state before the switchover. Read business requests from the cache queue and replay them sequentially to the new primary node, ensuring data integrity. Write channel recovery: Reopen the database write channel, allowing normal data writing to continue.
[0045] Based on the above embodiments, optionally, the pre-switching conditions include the primary node having a high risk of abnormality, or the primary node having a high risk of abnormality for a preset time.
[0046] Specifically, this invention provides two strategies for handling anomaly risks. The first strategy is to perform a master-slave pre-switch as soon as the primary node's anomaly risk is deemed high. This strategy can respond to anomalies immediately and prevent their further escalation. However, excessively frequent master-slave pre-switches can increase database pressure and affect the normal processing of business requests. The second strategy, after determining that the primary node's anomaly risk is high, does not immediately perform a master-slave pre-switch. Instead, it observes for a preset time. If the primary node's anomaly risk remains high within the preset time, then a master-slave pre-switch is performed. The advantage of this strategy is that it avoids interference from anomalies caused by short-term business fluctuations on the master-slave pre-switch.
[0047] The embodiments of the present invention utilize a pre-switch process to proactively defend against environmental anomalies and avoid reactive responses, thereby ensuring the stable operation of the database.
[0048] Figure 3 This is a schematic diagram of a pre-switching device for primary and backup nodes, provided as another embodiment of the present invention. (See attached diagram.) Figure 3 As shown, the device includes:
[0049] The risk prediction module 310 is used to predict the abnormal risks of each primary node based on the performance of the nodes.
[0050] The lossless switching module 320 is used to seamlessly switch the services of the primary node to the corresponding backup node if there is an abnormal risk that meets the pre-switching conditions.
[0051] The pre-switching device for primary and backup nodes provided in the embodiments of the present invention can execute the pre-switching method for primary and backup nodes provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method.
[0052] Optionally, the lossless switching module 320 is specifically used for: caching the front-end services processed by the primary node and saving a consistent snapshot of the primary node before the pre-switching; pausing the database write channel and switching the primary and backup identities of the primary node and the corresponding backup node; restoring the consistent snapshot before the pre-switching; replaying the cached front-end service requests to the new primary node and resetting the database write channel.
[0053] Optionally, the risk prediction module 310 includes:
[0054] The performance determination unit is used to determine the performance of each primary node in the database in each detection index.
[0055] The risk prediction unit is used to determine that the main node has a high risk of anomaly if there is a detection indicator whose performance is lower than the corresponding performance threshold.
[0056] Optionally, the pre-switching conditions include the primary node having a high risk of abnormality, or the primary node having a high risk of abnormality for a preset period of time.
[0057] Optionally, the detection metrics include memory, disk, and network.
[0058] Optionally, the method further includes an apparatus that includes:
[0059] The report generation module is used to generate a primary / backup node anomaly report based on the relevant information of the previous lossless pre-switch if the abnormal risk of the new primary node also meets the pre-switch conditions within the observation period.
[0060] The report push module is used to push abnormal reports of the primary and backup nodes to the database operation and maintenance personnel.
[0061] The pre-switching device for primary and backup nodes, as further explained, can also execute the pre-switching method for primary and backup nodes provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method.
[0062] Figure 4A schematic diagram of an electronic device 40 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0063] like Figure 4 As shown, the electronic device 40 includes at least one processor 41 and a memory, such as a read-only memory (ROM) 42 or a random access memory (RAM) 43, communicatively connected to the at least one processor 41. The memory stores computer programs executable by the at least one processor. The processor 41 can perform various appropriate actions and processes based on the computer program stored in the ROM 42 or loaded from storage unit 48 into the RAM 43. The RAM 43 may also store various programs and data required for the operation of the electronic device 40. The processor 41, ROM 42, and RAM 43 are interconnected via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0064] Multiple components in electronic device 40 are connected to I / O interface 45, including: input unit 46, such as keyboard, mouse, etc.; output unit 47, such as various types of monitors, speakers, etc.; storage unit 48, such as disk, optical disk, etc.; and communication unit 49, such as network card, modem, wireless transceiver, etc. Communication unit 49 allows electronic device 40 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0065] Processor 41 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 41 performs the various methods and processes described above, such as the pre-flight method for primary and backup nodes.
[0066] In some embodiments, the pre-switch method for primary and backup nodes may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 48. In some embodiments, part or all of the computer program may be loaded into and / or installed on electronic device 40 via ROM 42 and / or communication unit 49. When the computer program is loaded into RAM 43 and executed by processor 41, one or more steps of the pre-switch method for primary and backup nodes described above may be performed. Alternatively, in other embodiments, processor 41 may be configured to perform the pre-switch method for primary and backup nodes by any other suitable means (e.g., by means of firmware).
[0067] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0068] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0069] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0070] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0071] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0072] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0073] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0074] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A pre-switching method for primary and backup nodes, characterized in that, The method includes: Predict the abnormal risks of each primary node based on the node's performance. If there is an abnormal risk that meets the pre-switch conditions for the primary node, then the services of the primary node will be pre-switched to the corresponding backup node without loss.
2. The method according to claim 1, characterized in that, The step of seamlessly pre-switching the services of the primary node to the corresponding backup node includes: The front-end services processed by the primary node are cached, and a consistent snapshot of the primary node is saved before the pre-switch. Pause the database write channel and switch the primary and backup identities of the primary node and the corresponding backup node; Restore the consistent snapshot prior to the pre-switch; Replay the cached front-end business requests to the new primary node and reset the database write channel.
3. The method according to claim 1, characterized in that, The method of predicting the abnormal risks of each primary node in the database based on the node's performance includes: For each primary node in the database, determine the performance of the primary node in each detection metric; If there are detection indicators whose performance is lower than the corresponding performance threshold, then the anomaly risk of the primary node is determined to be high risk.
4. The method according to claim 4, characterized in that, The detection metrics include memory, disk, and network.
5. The method according to claim 4, characterized in that, The pre-switch conditions include the primary node having a high risk of abnormality, or the primary node having a high risk of abnormality for a preset period of time.
6. The method according to claim 1, characterized in that, After the lossless pre-switch of services from the primary node to the corresponding backup node, the process further includes: If the abnormal risk of the new primary node also meets the pre-switch conditions within the observation period, a primary / backup node abnormality report will be generated based on the relevant information of the previous lossless pre-switch. The system pushes anomaly reports of the primary and backup nodes to the database's maintenance personnel.
7. A pre-switching device for primary and backup nodes, characterized in that, The device includes: The risk prediction module is used to predict the abnormal risks of each primary node based on the performance of the nodes. The lossless switching module is used to seamlessly switch the services of the primary node to the corresponding backup node if there is an abnormal risk that meets the pre-switching conditions.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the pre-switch method for primary and backup nodes as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that are used to cause a processor to execute the pre-switching method for primary and backup nodes as described in any one of claims 1-6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the pre-switch method for primary / backup nodes as described in any one of claims 1-6.