Database cluster switching method and device
By performing switching pre-checks during database cluster switching, and performing read-only state transitions and disaster recovery switching when conditions are met, the problem of slow switching speed in the existing technology is solved, and fast and reliable cluster switching is achieved.
Patent Information
- Application Number
- CN202411708580.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-07
Smart Images

Figure CN119576660A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of database technology, and in particular to a database cluster switching method and device. Background Art
[0002] A cluster is a group of independent computers connected via a high-speed network. They form a group and are managed as a single system. Database cluster is the application of cluster in the database field. In addition to the main cluster, the database environment of high-level applications also requires the construction of a disaster recovery cluster, i.e., a backup cluster. When switching from the main cluster to the backup cluster, it is usually necessary to ensure the high availability of the system and the consistency of the data.
[0003] The existing database cluster switching method is slow and cannot quickly complete the switching between the primary and standby clusters. Summary of the invention
[0004] The present invention provides a database cluster switching method and device to solve the problem that the prior art cannot quickly complete the fast switching between the primary and standby clusters.
[0005] According to one aspect of the present invention, a database cluster switching method is provided, comprising:
[0006] After receiving the cluster switching instruction, determine whether the result of the switching pre-check meets the switching condition;
[0007] If yes, convert the primary cluster and the standby cluster to a read-only state, and send a database disaster recovery switch command to the primary cluster and the standby cluster at the same time, so as to control the primary cluster to execute the downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute the upgrade process to be upgraded to a new primary cluster;
[0008] The disaster recovery relationship between the new primary cluster and the new backup cluster is restored, and the cluster status information in the database management platform is modified.
[0009] According to another aspect of the present invention, there is provided a database cluster switching device, comprising:
[0010] A determination module, configured to determine whether a result of a pre-switching check satisfies a switching condition after receiving a cluster switching instruction;
[0011] A switching module is used to, if yes, convert the primary cluster and the standby cluster to a read-only state, and simultaneously issue a database disaster recovery switching command to the primary cluster and the standby cluster, so as to control the primary cluster to execute a downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute a upgrade process to be upgraded to a new primary cluster;
[0012] The modification module is used to restore the disaster recovery relationship between the new primary cluster and the new backup cluster, and to modify the cluster status information in the database management platform.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] at least one processor;
[0015] and a memory communicatively coupled to the at least one processor;
[0016] 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 so that the at least one processor can execute the database cluster switching method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the database cluster switching method described in any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the database cluster switching method according to any embodiment of the present invention is implemented.
[0019] The technical solution of the embodiment of the present invention, after receiving the cluster switching instruction, determines that the result of the pre-switching check meets the switching condition, converts the main cluster and the standby cluster to a read-only state, and simultaneously issues a database disaster recovery switching command to the main cluster and the standby cluster, so as to control the main cluster to execute the standby downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute the master upgrade process to be upgraded to a new main cluster; restore the disaster recovery relationship between the new main cluster and the new standby cluster, and modify the cluster status information in the database management platform, thereby solving the problem that the prior art cannot quickly complete the fast switching between the main and standby clusters, and achieving the beneficial effect of effectively shortening the cluster switching time.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 A schematic diagram of a process flow of a database cluster switching method provided in the first embodiment of the present invention;
[0023] Figure 2 A schematic diagram of a flow chart of a database cluster switching method provided in Embodiment 2 of the present invention;
[0024] Figure 3 A schematic diagram of the structure of a database cluster switching device provided in Embodiment 3 of the present invention;
[0025] Figure 4 The present invention is a schematic diagram of the structure of an electronic device for a database cluster switching method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only an embodiment of a part of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work should belong to the scope of protection of the present invention. It should be understood that the various steps recorded in the method implementation of the present invention can be performed in different orders and / or in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0027] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.
[0031] The complete database cluster switching process includes the following steps:
[0032] Step 1: Check before switching.
[0033] This includes confirming the health status of the master node and ensuring that there are no major failures; checking whether there is a log backlog and the status of the master and standby database instance components.
[0034] The specific contents of the pre-switching check include: data consistency check, network connection check, system resource check, database status check, replication status check, configuration file check, log file check and application session check.
[0035] Step 2: Ensure WAL log synchronization.
[0036] Ensure that the WAL logs between the primary cluster and the standby cluster are synchronized.
[0037] For example, check the WAL position on the primary cluster; check the last replayed WAL position on the standby cluster; or check the system views related to database data synchronization.
[0038] Step 3: Stop the master node.
[0039] Stop the master node on the primary cluster to prevent data inconsistency. If the master node is already unavailable, you can skip this step.
[0040] Step 4: Promote the backup node to the primary node in the standby cluster.
[0041] Step 5: Verify the status of the new master node.
[0042] Step 6: Reconfigure the original master node as a backup node.
[0043] Reconfigure the original primary node as a backup node, clear the old data directory, and create a base backup from the new primary node.
[0044] Step 7: Update the streaming replication configuration.
[0045] Make sure that streaming replication between the new primary and backup nodes is configured correctly.
[0046] Embodiment 1
[0047] Figure 1 A flow chart of a database cluster switching method provided in Embodiment 1 of the present invention is applicable to the case where a primary cluster switches to a backup cluster in a campus-level or regional-level failure scenario. The method can be executed by a database cluster switching device, wherein the device can be implemented by software and / or hardware and is generally integrated on an electronic device. In this embodiment, the electronic device includes but is not limited to: a computer device.
[0048] like Figure 1 As shown, a database cluster switching method provided in Embodiment 1 of the present invention includes the following steps:
[0049] S110: After receiving the cluster switching instruction, determine whether the result of the switching pre-check satisfies the switching condition.
[0050] The cluster switching instruction is sent by a user, and the cluster switching instruction may be an instruction to instruct to perform cluster switching.
[0051] In this embodiment, the pre-switching check is a pre-check of the disaster recovery process. If the check fails, the switching process will not be initiated. The pre-switching check may include important checks such as cluster status check, network status check, and version check. The pre-switching check finds potential problems before the cluster switching to avoid unexpected situations during the cluster switching process, ensures the consistency of the data of the master and standby nodes, and prevents data loss or inconsistency. Ensure that the system resources are sufficient to prevent the system performance from degrading after the switch; usually, the pre-switching check may take several minutes to more than ten minutes. Separating the pre-switching check from the cluster switching process can directly shorten the switching time to several seconds to several minutes.
[0052] In this embodiment, the pre-switching check is set to be performed before the cluster switching, and the pre-switching check is performed once at a preset interval. The time for performing the pre-switching check is not included in the cluster switching time. Before the cluster switching, the result of the last pre-switching check can be directly obtained to determine whether the result meets the switching condition. If the check result passes, the switching condition is met.
[0053] Furthermore, the pre-switching check is set to be a periodically invoked mode, and the result of the pre-switching check is the result of the pre-switching check that is most recent to the time when the cluster switching instruction is received.
[0054] For example, a pre-switching check is performed at 5:00, a pre-switching check is performed at 5:30, and a pre-switching check is performed at 6:00. If the cluster switching instruction is received at 6:20, the result of the pre-switching check performed at 6:00 can be obtained.
[0055] S120: If yes, convert the primary cluster and the standby cluster to a read-only state, and simultaneously issue a database disaster recovery switch command to the primary cluster and the standby cluster to control the primary cluster to execute a downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute a upgrade process to be upgraded to a new primary cluster.
[0056] In this embodiment, if the result of the pre-switching check meets the switching condition, the master data node of the active cluster can set the read-write state to the read-only state, and the master node of the standby cluster can set the read-write state to the read-only state.
[0057] In this embodiment, after the primary cluster and the standby cluster are converted to a read-only state, a database disaster recovery switching command can be issued to the standby cluster at the same time as the database disaster recovery switching command is issued to the primary cluster. The database disaster recovery switching instruction is initiated by the user; the database disaster recovery switching refers to downgrading the original primary cluster to the standby cluster and upgrading the original standby cluster to the primary cluster through the switching process, which can be understood as the database disaster recovery switching command issued to the primary cluster is a command to downgrade the primary cluster to the standby cluster; the database disaster recovery switching command issued to the standby cluster is a command to upgrade the standby cluster to the primary cluster.
[0058] In this embodiment, after receiving the database disaster recovery switch command, the primary cluster can execute the downgrade process to be downgraded to a new standby cluster, and the standby cluster can execute the upgrade process to be upgraded to a new primary cluster. The downgrade process can be understood as the process of downgrading the primary cluster to a new standby cluster, and the upgrade process can be understood as the process of upgrading the standby cluster to a new primary cluster.
[0059] It should be noted that the downgrade process and the upgrade process are executed simultaneously, and the initiation frequency of the downgrade process and the upgrade process is increased.
[0060] S130: Restore the disaster recovery relationship between the new primary cluster and the new backup cluster, and modify the cluster status information in the database management platform.
[0061] In this embodiment, after the disaster recovery relationship between the new primary cluster and the new standby cluster is established, the read-only state of the new primary cluster and the read-only state of the new standby cluster may be closed.
[0062] Among them, modifying the cluster status information in the database management platform may include: modifying the status information of the original primary cluster to the standby cluster, and modifying the status information of the original standby cluster to the primary cluster.
[0063] A database cluster switching method provided in the first embodiment of the present invention first determines whether the result of the pre-switching check meets the switching condition after receiving the cluster switching instruction; then, if so, the main cluster and the backup cluster are converted to a read-only state, and a database disaster recovery switching command is issued to the main cluster and the backup cluster at the same time, so as to control the main cluster to execute the downgrade process to downgrade to a new backup cluster while controlling the backup cluster to execute the upgrade process to upgrade to a new main cluster; finally, the disaster recovery relationship between the new main cluster and the new backup cluster is restored, and the cluster status information in the database management platform is modified. The above method separates the pre-switching check from the cluster switching process, and executes the downgrade process and the upgrade process simultaneously, which can effectively shorten the cluster switching time.
[0064] Furthermore, a post-switching check is performed after the database cluster switching is completed.
[0065] The post-switching check includes checking the running status of the database management system.
[0066] Specifically, the post-switch check may include checking system resources and network connectivity, as well as the status and disaster recovery relationship of the primary and standby database instance components.
[0067] It should be noted that the post-switching check is performed after the cluster switching is completed, and the time of the post-switching check is not included in the total time of the cluster switching.
[0068] Furthermore, after the cluster switch is completed, the risk point is repaired.
[0069] Among them, there may be multiple risk points after the cluster switch is completed, including the following risks and disposal solutions:
[0070] Risk point: Data inconsistency risk; before the primary node stops, the WAL log may not be fully synchronized to the standby cluster, resulting in data inconsistency.
[0071] Disposal solutions include: post-data verification and manual data repair;
[0072] Post-data verification: After the switch, immediately perform data consistency verification to compare the data of the new primary node and the backup node. For example, compare the data consistency of a key table;
[0073] Manual data repair: If data inconsistency is found, repair the inconsistent data by inserting missing data.
[0074] Risk points: Unconfirmed node status risk; the master node status has not been checked, and there may be data corruption or other anomalies.
[0075] The disposal plan includes: quick status check and system log check;
[0076] Quick status check: Check the health status of the new master node immediately after the switch;
[0077] System log check: Check the system log to ensure that the new master node is running normally and there are no major errors.
[0078] Risk point: Insufficient resources risk. After the standby cluster switches to the active cluster, system resources such as CPU, memory, and disk space may be insufficient, resulting in performance degradation.
[0079] The disposal solutions include: resource monitoring and dynamic resource allocation;
[0080] Resource monitoring: monitor system resource usage immediately after switching to ensure sufficient resources;
[0081] Dynamic resource allocation: Dynamically adjust resource allocation or add resources based on monitoring results.
[0082] Risk point: Network connection problem risk; the network connection between the primary and backup nodes may be unstable, resulting in failure to synchronize data normally after switching.
[0083] The solutions include: network connectivity check and reestablishing replication connection;
[0084] Network connectivity check: Check the network connectivity between the active and standby nodes immediately after the switch;
[0085] Rebuild replication connections: If there are network issues, reconfigure and rebuild replication connections.
[0086] Risk point: Risk of failure of automation tools; tool failure may lead to failed or incomplete switching.
[0087] Disposal options include: tool pre-inspection and maintenance and backup manual options;
[0088] Tool pre-check and maintenance: Regularly check and maintain automation tools and scripts to ensure they are working properly;
[0089] Backup manual plan: Prepare a backup manual switch plan in case the automation tool fails.
[0090] Risk point: Switching anomaly; in the small probability that the switching conditions are not met, the switching cannot be achieved.
[0091] The disposal plan includes: stopping the switch, restoring the original primary cluster, and restoring the production cluster to the state before the switch.
[0092] Risk point: risk of log loss; when the master node stops, there may be logs that have not been persisted, resulting in log loss.
[0093] The disposal solutions include: WAL archive check and manual archive log;
[0094] WAL archive check: Check the WAL archive status after switching to ensure that all logs have been archived.
[0095] Manually archive logs: If you find that the logs are not archived, manually archive the logs.
[0096] Embodiment 2
[0097] Figure 2 This is a flow chart of a database cluster switching method provided by Embodiment 2 of the present invention. Embodiment 2 is optimized on the basis of the above embodiments. For details not yet fully described in this embodiment, please refer to Embodiment 1.
[0098] like Figure 2 As shown, a database cluster switching method provided by Embodiment 2 of the present invention includes the following steps:
[0099] S210: After receiving the cluster switching instruction, determine whether the result of the switching pre-check satisfies the switching condition.
[0100] S220: If yes, convert the primary cluster and the standby cluster to a read-only state, and simultaneously send a database disaster recovery switch command to the primary cluster and the standby cluster.
[0101] After step S220 is completed, step S230 and step S240 are executed simultaneously.
[0102] S230: After receiving the database disaster recovery switch command, control the standby cluster to send information on whether to enter the switch process to the active cluster at a preset time interval.
[0103] The frequency of sending the information on whether to enter the switching process is set to be higher than the normal value.
[0104] For example, in the prior art, the information on whether to enter the switching process is sent once every 60 seconds, while in this embodiment, the information on whether to enter the switching process is sent once every 20 seconds.
[0105] S231 . After receiving the information from the primary cluster confirming the entry into the switching process, the standby cluster is controlled to initiate a redo log synchronization request to the primary cluster, so that the primary cluster executes redo log synchronization.
[0106] During database operations, such as inserting, updating, and deleting data, the database system will not only make corresponding modifications to the data files in the database directly, but also record these operations in a specific format in the redo log file; the redo log contains information sufficient to reconstruct or replay these operations, such as the type of operation, the address of the data blocks involved, the values before and after the modification, etc.
[0107] When a database system fails (such as a sudden power outage, system crash, etc.), the data modifications in the memory may be lost before they are completely written to the data file. The redo log synchronization mechanism can ensure that when recovering from a failure, the database is restored to a consistent state before the failure by re-executing the operations in the redo log, thereby ensuring that data will not be lost due to failures and achieving data persistence.
[0108] The redo log synchronization performed by the primary cluster may include:
[0109] 1. Log writing: When a transaction in the database performs a data modification operation, the data is first modified in the memory buffer of the database system; at the same time, the redo log information related to the modification operation is generated and written to the redo log buffer in the memory.
[0110] 2. Log flushing: To ensure that the redo log is not lost when a failure occurs, the contents of the redo log buffer in the memory need to be flushed to the redo log file on the disk periodically or under specific conditions.
[0111] 3. Synchronization confirmation: After flushing the redo log from the buffer to the disk, the database system usually waits for the confirmation signal of the disk I / O operation completion. Only when this confirmation signal is received, it means that the redo log synchronization process is truly completed.
[0112] S232: Modify the standby cluster to be a new active cluster.
[0113] Specifically, modifying the standby cluster to be a new active cluster includes modifying cluster parameters of the standby cluster to cluster parameters of the active cluster.
[0114] In this embodiment, to change the standby cluster to the active cluster, it is only necessary to modify the cluster parameters, and the cluster restart is replaced by the online parameter taking effect.
[0115] S240 , after receiving the database disaster recovery switch command, the active cluster receives information from the standby cluster on whether to enter a switch process, and feeds back information confirming the entry into the switch process to the standby cluster.
[0116] In this embodiment, after the standby cluster receives the database disaster recovery switching command sent by the user, it can send information on whether to enter the switching process to the active cluster; after the active cluster receives the information on whether to enter the switching process, if it confirms to enter the switching process, it can feedback the information confirming to enter the switching process to the standby cluster.
[0117] S241. Control the primary cluster to asynchronously perform file operations and redo log synchronization.
[0118] The file operation may include stopping data backup, deleting archived data, and deleting OBS files.
[0119] In this embodiment, the file operation and the redo log synchronization can be performed asynchronously, and there is no need to wait for the asynchronous execution to end before the redo log synchronization.
[0120] S242: Modify the primary cluster to a new secondary cluster.
[0121] Specifically, modifying the active cluster to be a new standby cluster includes modifying cluster parameters of the active cluster to cluster parameters of the standby cluster.
[0122] In this embodiment, to change the primary cluster to the standby cluster, it is only necessary to modify the cluster parameters, and the cluster restart is replaced by the online parameter taking effect.
[0123] S250: Restore the disaster recovery relationship between the new primary cluster and the new backup cluster, and modify the cluster status information in the database management platform.
[0124] The second embodiment of the present invention provides a database cluster switching method, which specifically implements the process of the primary cluster executing the downgrade process to be downgraded to a new standby cluster and the standby cluster executing the upgrade process to be upgraded to a new primary cluster. The method can effectively shorten the cluster switching time.
[0125] Embodiment 3
[0126] Figure 3 This is a structural diagram of a database cluster switching device provided in Example 3 of the present invention. The device can be used in the case where a primary cluster switches to a backup cluster in a campus-level or regional-level failure scenario. The device can be implemented by software and / or hardware and is generally integrated on an electronic device.
[0127] like Figure 3 As shown, the device includes: a determination module 110 , a switching module 120 and a modification module 130 .
[0128] The determination module 110 is used to determine whether the result of the pre-switching check meets the switching condition after receiving the cluster switching instruction;
[0129] The switching module 120 is used to convert the primary cluster and the standby cluster to a read-only state if the primary cluster and the standby cluster are in the same state, and simultaneously issue a database disaster recovery switching command to the primary cluster and the standby cluster, so as to control the primary cluster to execute a downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute a upgrade process to be upgraded to a new primary cluster;
[0130] The modification module 130 is used to restore the disaster recovery relationship between the new active cluster and the new standby cluster, and to modify the cluster status information in the database management platform.
[0131] In this embodiment, the device first determines whether the result of the pre-switching check meets the switching condition after receiving the cluster switching instruction through the determination module 110; then converts the main cluster and the standby cluster to a read-only state through the switching module 120, and simultaneously issues a database disaster recovery switching command to the main cluster and the standby cluster to control the main cluster to execute the downgrade process to downgrade to a new standby cluster while controlling the standby cluster to execute the upgrade process to upgrade to a new main cluster; finally, the disaster recovery relationship between the new main cluster and the new standby cluster is restored through the modification module 130, and the cluster status information in the database management platform is modified.
[0132] This embodiment provides a database cluster switching device, which can effectively shorten the cluster switching time.
[0133] Further, the pre-switching check is set to be a periodically invoked mode, and the result of the pre-switching check is the result of the pre-switching check that is most recent to the time when the cluster switching instruction is received.
[0134] Furthermore, the switching module 120 includes:
[0135] A sending unit, configured to control the standby cluster to send information on whether to enter a switching process to the active cluster at a preset interval after receiving the database disaster recovery switching command;
[0136] An initiating unit, configured to control the standby cluster to initiate a redo log synchronization request to the primary cluster after receiving the information from the primary cluster confirming the entry into the switching process, so that the primary cluster performs redo log synchronization;
[0137] The first modification unit is used to modify the standby cluster to be a new active cluster.
[0138] On the basis of the above optimization, the first modifying unit is specifically used to modify the cluster parameters of the standby cluster to the cluster parameters of the active cluster.
[0139] Based on the above technical solution, the sending frequency of the information on whether to enter the switching process is set to be higher than the normal value.
[0140] Furthermore, the switching module 120 includes:
[0141] A feedback unit, configured to control the active cluster to receive information sent by the standby cluster on whether to enter a switching process after receiving the database disaster recovery switching command, and to feed back information confirming the entry into the switching process to the standby cluster;
[0142] An execution unit, used to control the primary cluster to asynchronously execute file operations and redo log synchronization;
[0143] The second modification unit is used to modify the active cluster into a new standby cluster.
[0144] Based on the above optimization, file operations include stopping data backup, deleting archived data, and deleting OBS files.
[0145] Based on the above technical solution, the second modification unit is specifically configured to modify the cluster parameters of the active cluster to the cluster parameters of the standby cluster.
[0146] Further, the device also includes a check module, which is used to perform a post-switching check after the database cluster switch is completed;
[0147] The post-switching check includes checking the running status of the database management system.
[0148] The above-mentioned database cluster switching device can execute the database cluster switching method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0149] Embodiment 4
[0150] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment 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 processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0151] like Figure 4As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0152] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0153] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a database cluster switching method.
[0154] In some embodiments, the database cluster switching method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps in the database cluster switching method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the database cluster switching method in any other appropriate manner (e.g., by means of firmware).
[0155] Various implementations 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 chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0156] In some embodiments, the database cluster switching method may be implemented as a computer program, which is invisibly included in a computer program product. The computer program implements the database cluster switching method of the present invention when executed by a processor. The computer program product can be understood as a software product that implements its solution mainly through a computer program. The computer program for implementing the method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the computer program, when executed by the processor, enables the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer program can be executed entirely on the machine, partially on the machine, partially on the machine as an independent software package and partially on a remote machine, or entirely on a remote machine or server.
[0157] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer 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 foregoing.
[0158] To provide interaction with a user, the systems and techniques described herein may 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 a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0159] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0160] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0161] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0162] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A database cluster switching method, characterized in that: The method comprises: After receiving the cluster switching instruction, determine whether the result of the switching pre-check meets the switching condition; If yes, convert the primary cluster and the standby cluster to a read-only state, and send a database disaster recovery switch command to the primary cluster and the standby cluster at the same time, so as to control the primary cluster to execute the downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute the upgrade process to be upgraded to a new primary cluster; The disaster recovery relationship between the new primary cluster and the new backup cluster is restored, and the cluster status information in the database management platform is modified.
2. The method according to claim 1, characterized in that The pre-switching check is set to be a periodically invoked mode, and the result of the pre-switching check is the result of the pre-switching check that is most recent to the time when the cluster switching instruction is received.
3. The method according to claim 1, characterized in that Controlling the standby cluster to execute a standby upgrade process to upgrade to a new active cluster, including: After receiving the database disaster recovery switching command, the standby cluster is controlled to send information on whether to enter the switching process to the main cluster at a preset interval; After the standby cluster receives the information from the primary cluster confirming the entry into the switching process, it initiates a redo log synchronization request to the primary cluster, so that the primary cluster performs redo log synchronization; Modify the standby cluster to be a new active cluster.
4. The method according to claim 3, characterized in that The modifying the standby cluster to be a new active cluster includes: modifying cluster parameters of the standby cluster to cluster parameters of the active cluster.
5. The method according to claim 3, characterized in that: The sending frequency of the information on whether to enter the switching process is set to be higher than the normal value.
6. The method according to claim 1, characterized in that Controlling the main cluster to execute a downgrade process to downgrade to a new standby cluster includes: After receiving the database disaster recovery switch command, the active cluster receives information from the standby cluster about whether to enter the switch process, and feeds back information confirming the entry into the switch process to the standby cluster; Controlling the primary cluster to asynchronously perform file operations and redo log synchronization; Modify the primary cluster to be a new secondary cluster.
7. The method according to claim 6, characterized in that The file operations include stopping data backup, deleting archived data, and deleting OBS files.
8. The method according to claim 6, characterized in that The modifying the primary cluster to be a new standby cluster includes: modifying cluster parameters of the primary cluster to cluster parameters of the standby cluster.
9. The method according to claim 1, characterized in that: The method further comprises: Perform post-switching checks after the database cluster switch is complete; The post-switching check includes checking the running status of the database management system.
10. A database cluster switching device, characterized in that: The device comprises: A determination module, configured to determine whether a result of a pre-switching check satisfies a switching condition after receiving a cluster switching instruction; A switching module is used to, if yes, convert the primary cluster and the standby cluster to a read-only state, and simultaneously issue a database disaster recovery switching command to the primary cluster and the standby cluster, so as to control the primary cluster to execute a downgrade process to be downgraded to a new standby cluster and control the standby cluster to execute a upgrade process to be upgraded to a new primary cluster; The modification module is used to restore the disaster recovery relationship between the new primary cluster and the new backup cluster, and to modify the cluster status information in the database management platform.