Database switching methods, devices, computer equipment, and readable storage media
By employing a multi-process polling detection and failover approach, the problems of long detection times and low switching efficiency caused by a large number of database clusters are solved, enabling rapid fault detection and business transfer.
Patent Information
- Application Number
- CN202211426061.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-15
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2042-11-15
AI Technical Summary
When there are many database clusters, single-process polling and probing takes too long, making it difficult to detect faults in a timely manner, resulting in low database switching efficiency.
A multi-process approach is used to poll and probe multiple database clusters. By acquiring metadata information, the status of the database clusters is extracted, and the clusters to be adjusted are identified from the probe results. The databases are then selected as the new primary databases, and services are transferred to achieve failover.
It shortened the overall time of polling and probing, improved the timeliness of database fault detection and switching efficiency, and ensured business continuity.
Smart Images

Figure CN115794466B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of database operation and maintenance technology, and more specifically, relates to a database switching method, apparatus, computer equipment and readable storage medium. Background Technology
[0002] A high-availability cluster refers to a cluster where, when a server fails, its services, resources, IP addresses, etc., can be transferred to another server to ensure business continuity. These two or more servers constitute a high-availability cluster.
[0003] In practical applications, high-availability database architectures often involve multiple database clusters, each containing multiple databases. When probing the status of these clusters, a single process is typically used to establish a connection with each database in each cluster sequentially to identify their status. However, the applicant recognizes that as the number of monitored database clusters increases, polling multiple clusters with a single process leads to excessive time consumption. Specifically, during polling, a connection needs to be established with each database in the cluster; the more clusters there are, the longer the polling process becomes. This significant time consumption hinders timely detection of database failures, resulting in inefficient database failover. Summary of the Invention
[0004] In view of this, the present invention provides a database switching method, apparatus, computer equipment and readable storage medium, the main purpose of which is to solve the problem that current database detection consumes a lot of time, making it difficult to detect database faults in a timely manner, resulting in low database switching efficiency.
[0005] According to a first aspect of the present invention, a database switching method is provided, comprising:
[0006] The system acquires multiple metadata information and extracts multiple database cluster status information from the multiple metadata information, wherein the multiple metadata information is collected from the multiple database clusters by the anomaly detector when it detects a read operation on multiple database clusters;
[0007] Based on the status information of the multiple database clusters, a multi-process polling probe is used to detect the status of the multiple database clusters to obtain the probe result corresponding to each database cluster. The probe result corresponding to the database cluster includes the probe success flag or probe failure flag returned by each database in the database cluster.
[0008] Among the plurality of database clusters, a database cluster to be adjusted is determined, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers;
[0009] In the database cluster to be adjusted, a slave database is selected as the new master database, and the business being processed by the current master database in the database cluster to be adjusted is transferred to the new master database. The database cluster to be adjusted includes a master database and multiple slave databases.
[0010] Optionally, before obtaining the multiple metadata information, the method further includes:
[0011] In response to the polling and probing requests of the multiple database clusters, the anomaly detector is run, and when the anomaly detector detects that it is performing a read operation on the multiple database clusters, metadata information of each database cluster in the multiple database clusters is collected.
[0012] Multiple sublists are generated based on the multiple database clusters. Each sublist includes multiple database cluster identification information, and each database cluster identification information indicates a database cluster.
[0013] Optionally, in response to the polling and probing requests for the plurality of database clusters, the anomaly detector is run. Upon detecting that the anomaly detector performs a read operation on the plurality of database clusters, metadata information of each database cluster is collected, including:
[0014] The anomaly detector is run to perform the following operations on each database in each database cluster: send a database probe request to the database, continuously collect timeout anomaly information, when the timeout anomaly information is collected, continue to send a database probe request to the database, when the timeout anomaly information is not collected, collect the corresponding sub-metadata information of the database, when the database probe request is sent to the database again, continue to collect the timeout anomaly information, when the timeout anomaly information is collected again, continue to send a database probe request to the database within a preset number of times until the corresponding sub-metadata information of the database is collected, wherein the timeout anomaly information is returned by the database in response to the database probe request;
[0015] Based on the collected sub-metadata information corresponding to each database in each database cluster, the metadata information of each database cluster in the plurality of database clusters is obtained.
[0016] Optionally, generating multiple sub-lists based on the multiple database clusters includes:
[0017] Use list comprehension to generate multiple list templates;
[0018] Based on the number of the multiple database clusters and the number of the multiple list templates, the preset number of database clusters included in each list template is obtained by modulo operation;
[0019] Based on the preset number of database clusters included in each list template, the identification information of the multiple database clusters is sequentially assigned to the multiple list templates to obtain the multiple sub-lists.
[0020] Optionally, the step of using multiple processes to poll and probe the database cluster status of the multiple database clusters based on the status information of the multiple database clusters, and obtaining the probe result corresponding to each database cluster, includes:
[0021] Based on the metadata information of each database cluster, multiple probe areas are determined for each database cluster, and each probe area corresponds to a database in the database cluster;
[0022] A process is used to poll and probe the status of multiple database clusters indicated by the identification information of multiple database clusters in a sublist. When polling and probing the database clusters, the following operations are performed on each database: sending a database probe request carrying a preset protocol to the probe area corresponding to the database, and receiving a probe result returned by the database in response to the database probe request carrying the preset protocol.
[0023] Other processes are used to poll and probe the status of the multiple database clusters indicated by the multiple database cluster identification information in the other sublists to obtain other probe results, wherein the other processes are processes other than the one process mentioned above.
[0024] Optionally, determining the database cluster to be adjusted among the plurality of database clusters, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers, includes:
[0025] The number of successful probes and the number of failed probes in a database cluster are counted. When the number of successful probes is less than the number of failed probes, the database cluster is determined to be a database cluster that needs to be adjusted.
[0026] Continue to count the number of successful probes and the number of failed probes in other database clusters. When the number of successful probes is less than the number of failed probes, determine that the other database cluster is another database cluster to be adjusted. The other database cluster is the database cluster other than the first database cluster among the multiple database clusters.
[0027] Optionally, the method further includes:
[0028] Run the health detector to obtain the configuration information of the new master database, including the IP address and port information of the new master database;
[0029] Based on the configuration information, the system connects to the new primary database. When the health detector detects that the new primary database can perform read and write operations, the system determines that the new primary database is connected. When the health detector detects that the new primary database cannot perform read and write operations, the system determines that the new primary database is disconnected.
[0030] According to a second aspect of the present invention, a database switching device is provided, comprising:
[0031] An extraction module is used to acquire multiple metadata information and extract multiple database cluster status information from the multiple metadata information, wherein the multiple metadata information is collected from the multiple database clusters by the anomaly detector when it detects a read operation on multiple database clusters;
[0032] The detection module is used to poll and detect the status of the multiple database clusters using multiple processes based on the status information of the multiple database clusters, and obtain the detection result corresponding to each database cluster. The detection result corresponding to each database cluster includes the detection success identifier or detection failure identifier returned by each database in the database cluster.
[0033] The determination module is used to determine the database cluster to be adjusted among the plurality of database clusters, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers.
[0034] The switching module is used to select a slave database as the new master database in the database cluster to be adjusted, and to transfer the business being processed by the current master database in the database cluster to be adjusted to the new master database. The database cluster to be adjusted includes a master database and multiple slave databases.
[0035] Optionally, the device further includes:
[0036] The acquisition module is used to respond to the polling and probing requests of the multiple database clusters, run the anomaly detector, and when the anomaly detector detects that it is performing a read operation on the multiple database clusters, acquire the metadata information of each database cluster in the multiple database clusters.
[0037] The generation module is used to generate multiple sub-lists based on the multiple database clusters. Each sub-list includes multiple database cluster identification information, and each database cluster identification information indicates a database cluster.
[0038] Optionally, the acquisition module is further configured to run the anomaly detector and perform the following operations on each database in each database cluster: send a database probe request to the database, continuously collect timeout anomaly information, when the timeout anomaly information is collected, continue to send a database probe request to the database, when the timeout anomaly information is not collected, collect the corresponding sub-metadata information of the database, continue to collect the timeout anomaly information when sending a database probe request to the database, and continue to send a database probe request to the database within a preset number of times when the timeout anomaly information is collected, until the corresponding sub-metadata information of the database is collected, wherein the timeout anomaly information is returned by the database in response to the database probe request; and obtain the metadata information of each database cluster in the plurality of database clusters based on the collected sub-metadata information of each database in each database cluster.
[0039] The generation module is further configured to generate multiple list templates using a list comprehension method; based on the number of multiple database clusters and the number of multiple list templates, obtain a preset number of database clusters included in each list template through a modulo operation; and based on the preset number of database clusters included in each list template, sequentially allocate the multiple database cluster identification information to the multiple list templates to obtain the multiple sub-lists.
[0040] Optionally, the detection module is further configured to determine multiple detection areas corresponding to each database cluster based on the metadata information of each database cluster, wherein each detection area corresponds to a database in the database cluster; use a process to poll and detect the status of the multiple database clusters indicated by the identification information of the multiple database clusters in a sublist; when polling and detecting the database clusters, perform the following operations for each database: send a database detection request carrying a preset protocol to the detection area corresponding to the database, and receive a detection result returned by the database in response to the database detection request carrying the preset protocol; use other processes to poll and detect the status of the multiple database clusters indicated by the identification information of the multiple database clusters in other sublists, and obtain other detection results, wherein the other processes are processes other than the first process among the multiple processes.
[0041] Optionally, the determining module is further configured to count the number of successful probe identifiers and the number of failed probe identifiers in a database cluster, and when the number of successful probe identifiers is less than the number of failed probe identifiers, determine that the database cluster is a database cluster to be adjusted; continue to count the number of successful probe identifiers and the number of failed probe identifiers in other database clusters, and when the number of successful probe identifiers is less than the number of failed probe identifiers, determine that the other database cluster is another database cluster to be adjusted, wherein the other database cluster is the database cluster other than the first database cluster among the plurality of database clusters.
[0042] Optionally, the device further includes:
[0043] The acquisition module is used to run the health detector and acquire the configuration information of the new master database, including the IP address and port information of the new master database.
[0044] The detection module is used to connect to the new primary database based on the configuration information. When the health detector detects that the new primary database can perform read and write operations, it determines that the connectivity status of the new primary database is connectable. When the health detector detects that the new primary database cannot perform read and write operations, it determines that the connectivity status of the new primary database is disconnected.
[0045] According to a third aspect of the present invention, a computer device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described in any one of the first aspects above.
[0046] According to a fourth aspect of the present invention, a readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any one of the first aspects above.
[0047] By employing the above technical solution, this application provides a database switching method. First, it acquires multiple metadata information and extracts multiple database cluster status information from this metadata. Then, based on the multiple database cluster status information, it uses a multi-process approach to poll and probe the database cluster status of the multiple database clusters, obtaining the probe results for each database cluster. Subsequently, it identifies the database cluster to be adjusted from among the multiple database clusters, ensuring that the number of probe failure markers in the probe results for the database cluster to be adjusted is greater than the number of probe success markers. Finally, it selects a slave database from the database cluster to be adjusted as the new master database and transfers the business currently being processed by the master database in the database cluster to the new master database. By using a multi-process approach, the database cluster status of multiple database clusters can be polled and probed simultaneously, shortening the overall polling and probing time. This solves the problem that current database probing consumes a large amount of time, making it difficult to detect database faults in a timely manner, resulting in low database switching efficiency.
[0048] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0049] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0050] Figure 1 A flowchart of a database switching method provided in an embodiment of this application is shown.
[0051] Figure 2 A flowchart of another database switching method provided in an embodiment of this application is shown.
[0052] Figure 3A A schematic diagram of the structure of a database switching device provided in an embodiment of this application is shown.
[0053] Figure 3B A schematic diagram of the structure of a database switching device provided in an embodiment of this application is shown.
[0054] Figure 3CA schematic diagram of the structure of a database switching device provided in an embodiment of this application is shown.
[0055] Figure 4 A schematic diagram of the device structure of a computer device provided in an embodiment of this application is shown. Detailed Implementation
[0056] Various embodiments and features of this application are described herein with reference to the accompanying drawings.
[0057] It should be understood that various modifications can be made to the embodiments described herein. Therefore, the above description should not be considered as limiting, but merely as an example of embodiments. Other modifications within the scope and spirit of this application will be apparent to those skilled in the art.
[0058] The accompanying drawings, which are included in and form part of this specification, illustrate embodiments of the present application and, together with the general description of the present application given above and the detailed description of the embodiments given below, serve to explain the principles of the present application.
[0059] These and other features of this application will become apparent from the following description of preferred forms of embodiments given as non-limiting examples, with reference to the accompanying drawings.
[0060] It should also be understood that although this application has been described with reference to some specific examples, those skilled in the art can certainly implement many other equivalent forms of this application.
[0061] The above and other aspects, features and advantages of this application will become more apparent when taken in conjunction with the accompanying drawings and in view of the following detailed description.
[0062] Specific embodiments of this application are described thereafter with reference to the accompanying drawings; however, it should be understood that the claimed embodiments are merely examples of this application, which can be implemented in various ways. Well-known and / or repeated functions and structures are not described in detail to avoid unnecessary or redundant details that could obscure the application. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but merely serve as the basis and representative basis for the claims to teach those skilled in the art to use this application in a variety of substantially any suitable detailed structures.
[0063] This specification may use the phrases “in one embodiment,” “in another embodiment,” “in yet another embodiment,” or “in other embodiments,” all of which may refer to one or more of the same or different embodiments according to this application.
[0064] This application provides a database switching method, such as... Figure 1 As shown, it includes:
[0065] 101. Obtain multiple metadata information and extract multiple database cluster status information from multiple metadata information.
[0066] In this embodiment of the application, after collecting metadata information of each database cluster in multiple database clusters, multiple metadata information is obtained, and multiple database cluster status information is extracted from the multiple metadata information. The multiple metadata information is collected from multiple database clusters by the anomaly detector when it detects that a read operation is performed on multiple database clusters.
[0067] 102. Based on the status information of multiple database clusters, a multi-process approach is used to poll and probe the status of multiple database clusters to obtain the probe results for each database cluster.
[0068] The inventors recognized that in practical applications, when probing the status of a database cluster, a single process is needed to establish a connection with each database in each cluster sequentially to identify the database's status. As the number of monitored database clusters increases, polling multiple clusters with a single process leads to prolonged processing time. Specifically, during polling multiple clusters, a connection needs to be established with each database in the cluster. The more database clusters there are, the longer the polling process takes. This significant time consumption makes it difficult to detect database faults in a timely manner, resulting in low database switching efficiency. Therefore, the inventors developed a multi-process approach to poll the status of multiple database clusters based on their status information. This approach yields a detection result for each cluster, including a success or failure flag returned by each database within the cluster.
[0069] It should be noted that the databases in the database clusters in this application embodiment are hosted on servers. The servers can be independent servers or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. This allows for polling and probing of the database cluster status of multiple database clusters, thereby realizing the technical solutions described in this application.
[0070] 103. Identify the database cluster to be adjusted among multiple database clusters, where the number of failed probes in the probe results corresponding to the database cluster to be adjusted is greater than the number of successful probes.
[0071] In this embodiment of the application, since some database clusters may fail during the process of polling and probing the status of multiple database clusters using multiple processes, it is necessary to determine which part of the database cluster has failed. That is, if the number of failure flags in the probe results corresponding to the database cluster is greater than the number of success flags, it can be determined that the database cluster has failed, and the database cluster that has failed is called the database cluster to be adjusted.
[0072] 104. In the database cluster to be adjusted, select one slave database as the new master database, and transfer the business being processed by the current master database in the database cluster to the new master database.
[0073] In this embodiment of the application, after determining the database cluster to be adjusted, in order to maintain the availability of the database and ensure that the business is not affected, it is necessary to select one of the slave databases in the database cluster to be adjusted as the new master database through failover, and transfer the business being processed by the current master database in the database cluster to the new master database.
[0074] Specifically, failover refers to the rapid activation of redundant or standby servers, systems, hardware, or networks to take over the work when an active service or application unexpectedly terminates. Failover is essentially the same as switchover, except that failover is usually completed automatically without warnings or manual intervention, while switchover requires manual intervention. For servers, systems, or networks requiring high availability and stability, system designers typically incorporate failover functionality. It's important to note that a database cluster supporting failover must include at least one master database and one slave database. When the master database fails, failover typically selects a slave database in the cluster as the new master database, and the business processes currently being handled by the master database are transferred to the new master database.
[0075] The method provided in this application first acquires multiple metadata information and extracts multiple database cluster status information from the metadata information. Then, based on the multiple database cluster status information, a multi-process approach is used to poll and probe the database cluster status of the multiple database clusters, obtaining the probe results for each database cluster. Subsequently, the database cluster to be adjusted is determined among the multiple database clusters, where the number of probe failure markers in the probe results for the database cluster to be adjusted is greater than the number of probe success markers. Finally, a slave database in the database cluster to be adjusted is selected as the new master database, and the business currently being processed by the master database in the database cluster to be adjusted is transferred to the new master database. By using a multi-process approach, the database cluster status of multiple database clusters can be polled and probed simultaneously, shortening the overall time consumption of polling and probing. This solves the problem that current database probing consumes a lot of time, making it difficult to detect database faults in a timely manner, resulting in low database switching efficiency.
[0076] This application provides a database switching method, such as... Figure 2 As shown, it includes:
[0077] 201. Collect metadata information for each database cluster in multiple database clusters, and generate multiple sub-lists based on multiple database clusters.
[0078] In this embodiment, before acquiring metadata information, an anomaly detector is run in response to polling and probing requests to multiple database clusters. When the anomaly detector detects that it is performing read operations on multiple database clusters, metadata information of each database cluster is collected. Specifically, the anomaly detector is run, and the following operations are performed on each database in each database cluster: a database probe request is sent to the database, and timeout anomaly information is continuously collected. When timeout anomaly information is collected, a database probe request is sent to the database again. When no timeout anomaly information is collected, the corresponding sub-metadata information of the database is collected. When a database probe request is sent to the database again, timeout anomaly information is continuously collected. When timeout anomaly information is collected again, a database probe request is sent to the database again within a preset number of times until the corresponding sub-metadata information of the database is collected. The timeout anomaly information is returned by the database in response to the database probe request. Based on the collected sub-metadata information of each database in each database cluster, the metadata information of each database cluster in the multiple database clusters is obtained.
[0079] For example, the anomaly detector sends a database probe request to the database. Within a preset time, such as 1 second, 2 seconds, etc., if no connection is established with the database, the database returns a timeout exception. If a connection is established with the database, the database does not return any information. Furthermore, the program in this embodiment directly collects the corresponding sub-metadata information of the database. For databases where a connection has not been established, the anomaly detector collects the timeout exception information returned by the database. The anomaly detector continues to send database probe requests to the database within a preset number of times until the corresponding sub-metadata information of the database is collected. In this embodiment, the preset number of times can be 3 times, 5 times, etc., and the setting of the preset number of times can be flexibly selected according to the actual situation. Databases that still cannot establish a connection within the preset number of times can be marked. It should be noted that the above program can be understood as the overall method of the present invention being implemented through a program. This program is a front-end provided to the user by the server hosting the database, through which the database cluster can be operated.
[0080] In this embodiment, multiple sub-lists are generated based on multiple database clusters. Each sub-list includes multiple database cluster identifiers, and each database cluster identifier indicates a database cluster. Specifically, multiple list templates are generated using a list generation method. Based on the number of database clusters and the number of list templates, a preset number of database clusters included in each list template is obtained through a modulo operation. Based on the preset number of database clusters included in each list template, the multiple database cluster identifiers are sequentially allocated to the multiple list templates to obtain multiple sub-lists. For example, if a list generator generates 4 list templates and the number of database clusters is 60, the preset number of database clusters included in each list template is obtained by dividing the number of database clusters by the number of list templates. In this embodiment, the preset number of database clusters included in each list template is 15. According to this preset number of database clusters, the 60 database cluster identifiers are sequentially allocated to the 4 list templates to form 4 sub-lists.
[0081] 202. Obtain multiple metadata information and extract multiple database cluster status information from multiple metadata information.
[0082] In this embodiment, metadata refers to data about data, or data describing data, descriptive information about data and information resources. Metadata is the most important data among all data. For example, "age," "height," "weight," and "personality" in a medical examination report are metadata because they are used to describe specific data / information. Similarly, library catalog information cards, video descriptions on video websites, and web page addresses on the internet are all metadata. Metadata can be divided into three main categories according to the object it describes: technical metadata, business metadata, and management metadata. The metadata in this embodiment can be technical metadata or other types of metadata; no specific limitation is made here.
[0083] 203. Based on the status information of multiple database clusters, a multi-process approach is used to poll and probe the status of multiple database clusters to obtain the probe results for each database cluster.
[0084] In this embodiment, multiple probe regions corresponding to each database cluster are determined based on the metadata information of each database cluster. Each probe region corresponds to a database in the database cluster. A process is used to poll and probe the states of multiple database clusters indicated by multiple database cluster identifiers in a sublist. When polling and probing the database clusters, the following operations are performed for each database: a database probe request carrying a preset protocol is sent to the probe region corresponding to the database; a probe result is received from the database in response to the database probe request carrying the preset protocol; other processes are used to poll and probe the states of multiple database clusters indicated by multiple database cluster identifiers in other sublists to obtain other probe results. These other processes are processes other than the first process among the multiple processes. For example, previously, polling and probing 60 database clusters sequentially using a single process took about 5 minutes. In this embodiment, 4 processes can be used simultaneously to poll and probe the states of 15 database clusters indicated by each sublist in 4 lists, taking about 1 minute. Therefore, using multiple processes to poll and probe the states of multiple database clusters significantly reduces the overall polling time.
[0085] For example, a database cluster includes three databases: one primary database, one backup primary database, and one standby database. Both the backup primary and standby databases are slave databases, but with a priority: the backup primary database has a higher priority than the standby database. When the primary database fails, the backup primary database is selected as the new primary database. For a database cluster with three databases, there are three probe areas: a production line application area, a database area, and a production line bastion host area. The production line application area simulates applications probing the database, the database area simulates the standby database probing the database, and the production line bastion host area simulates operations personnel probing the database. Therefore, based on the database cluster's metadata, the database cluster status information is extracted. The liveness of the corresponding database is probed from the three probe points—the production line bastion host area, the database area, and the production line application area—using both SSH and SQL protocols. If the database is alive, the returned probe result can be marked with a "Y"; if the database fails, the returned probe result can be marked with an "N".
[0086] 204. Identify the database cluster to be adjusted among multiple database clusters, where the number of failed probes in the probe results corresponding to the database cluster to be adjusted is greater than the number of successful probes.
[0087] For example, taking the database cluster in step 203 as an example, the three databases included in the database cluster are polled and probed. Each database will return the probe result. For example, two of the databases return probe results marked with N, and one database returns probe results marked with Y. That is, the number of N-marked data is greater than the number of Y-marked data, indicating that the master database in the database cluster has failed. It can be determined that the database cluster is a database cluster to be adjusted. Subsequently, it is necessary to perform failover on the database cluster to be adjusted, and transfer the business currently being processed by the master database to the backup master database according to priority.
[0088] 205. In the database cluster to be adjusted, select one slave database as the new master database, and transfer the business being processed by the current master database in the database cluster to the new master database.
[0089] 206. Run the health checker to obtain the configuration information of the new primary database and determine its connectivity status.
[0090] In practice, the inventors recognized that when a primary database in a database cluster fails, failover is used to select a secondary database in the cluster as the new primary database. However, after the database cluster switch, the corresponding metadata information will be marked as undetectable, making it difficult to determine whether a successful connection with the new database has been established. Based on this, the method of this application further includes: running a health detector to obtain the configuration information of the new primary database, including the IP address and port information of the new primary database, and connecting to the new primary database based on the configuration information. When the health detector detects that it can perform read and write operations on the new primary database, the connectivity status of the new primary database is determined to be connectable; when the health detector detects that it cannot perform read and write operations on the new primary database, the connectivity status of the new primary database is determined to be unconnectable. Through the above method, the connectivity status of the new primary database can be detected, thereby ensuring the survival of the new primary database to guarantee business continuity.
[0091] The method provided in this application first collects metadata information for each database cluster in multiple database clusters and generates multiple sub-lists based on the multiple database clusters. Then, it acquires multiple metadata information and extracts multiple database cluster status information from the metadata information. Subsequently, based on the multiple database cluster status information, it uses a multi-process approach to poll and probe the database cluster status of the multiple database clusters, obtaining the probe results for each database cluster. Then, it identifies the database cluster to be adjusted from among the multiple database clusters, where the number of probe failure markers in the probe results for the database cluster to be adjusted is greater than the number of probe success markers. Finally, it selects a slave database in the database cluster to be adjusted as the new master database and transfers the business currently being processed by the master database in the database cluster to the new master database. The primary database is then switched over. Finally, a health checker is run to obtain the new primary database's configuration information and determine its connectivity. By employing a multi-process approach to traverse and query multiple sub-lists—that is, simultaneously polling and probing the status of multiple database clusters indicated by multiple database cluster identifiers in each sub-list—the overall polling time is shortened. This addresses the current problem of excessive time spent on database probing, making it difficult to detect database faults in a timely manner and resulting in low database switchover efficiency. Simultaneously, by running the health checker to obtain the new primary database's configuration information and determine its connectivity, the issue of metadata information being marked as undetectable after a database cluster switchover, making it difficult to determine whether a successful connection to the new database has been established, thus compromising business continuity, is resolved.
[0092] Furthermore, as Figure 1 The specific implementation of the method is as follows: Figure 3AAs shown in the figure, this application embodiment provides a database switching device, including: an extraction module 301, a detection module 302, a determination module 303, and a switching module 304.
[0093] The extraction module 301 is used to acquire multiple metadata information and extract multiple database cluster status information from the multiple metadata information. The multiple metadata information is collected from multiple database clusters by the anomaly detector when it detects that read operations are performed on multiple database clusters.
[0094] The detection module 302 is used to poll and probe the status of multiple database clusters based on the status information of multiple database clusters using multiple processes, and obtain the detection result corresponding to each database cluster. The detection result corresponding to each database cluster includes the detection success flag or detection failure flag returned by each database in the database cluster.
[0095] The determining module 303 is used to determine the database cluster to be adjusted among multiple database clusters, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers.
[0096] The switching module 304 is used to select a slave database as the new master database in the database cluster to be adjusted, and to transfer the business being processed by the current master database in the database cluster to be adjusted to the new master database. The database cluster to be adjusted includes a master database and multiple slave databases.
[0097] In specific application scenarios, such as Figure 3B As shown, the device also includes: a data acquisition module 305 and a data generation module 306.
[0098] The acquisition module 305 is used to respond to the polling and probing request of the multiple database clusters, run the anomaly detector, and when the anomaly detector detects that it is performing a read operation on the multiple database clusters, acquire the metadata information of each database cluster in the multiple database clusters.
[0099] The generation module 306 is used to generate multiple sub-lists based on the multiple database clusters. Each of the multiple sub-lists includes multiple database cluster identification information, and each database cluster identification information indicates a database cluster.
[0100] In specific application scenarios, the acquisition module 305 is also used to run an anomaly detector, performing the following operations on each database in each database cluster: sending a database probe request to the database, continuously collecting timeout anomaly information; when timeout anomaly information is collected, continuing to send a database probe request to the database; when no timeout anomaly information is collected, collecting the corresponding sub-metadata information of the database; continuing to send a database probe request to the database, continuously collecting timeout anomaly information; when timeout anomaly information is collected again, continuously sending a database probe request to the database within a preset number of times until the corresponding sub-metadata information of the database is collected, wherein the timeout anomaly information is returned by the database in response to the database probe request; based on the collected sub-metadata information corresponding to each database in each database cluster, the metadata information of each database cluster in multiple database clusters is obtained.
[0101] The generation module 306 is also used to generate multiple list templates using list generation; based on the number of multiple database clusters and the number of multiple list templates, it obtains the preset number of database clusters included in each list template through modulo operation; based on the preset number of database clusters included in each list template, it sequentially distributes the identification information of multiple database clusters into multiple list templates to obtain multiple sub-lists.
[0102] In specific application scenarios, the detection module 302 is also used to determine multiple detection areas corresponding to each database cluster based on the metadata information of each database cluster, and each detection area corresponds to a database in the database cluster; a process is used to poll and probe the status of multiple database clusters indicated by multiple database cluster identification information in a sublist. When polling and probing the database clusters, the following operations are performed for each database: sending a database detection request carrying a preset protocol to the detection area corresponding to the database, and receiving a detection result returned by the database in response to the database detection request carrying the preset protocol; other processes are used to poll and probe the status of multiple database clusters indicated by multiple database cluster identification information in other sublists, and obtain other detection results, wherein the other processes are processes other than one of the multiple processes.
[0103] In specific application scenarios, the determining module 303 is also used to count the number of successful probes and the number of failed probes in a database cluster. When the number of successful probes is less than the number of failed probes, the database cluster is determined to be a database cluster to be adjusted. The module continues to count the number of successful probes and the number of failed probes in other database clusters. When the number of successful probes is less than the number of failed probes, the other database cluster is determined to be another database cluster to be adjusted. The other database clusters are the database clusters other than the first database cluster among multiple database clusters.
[0104] In specific application scenarios, such as Figure 3C As shown, the device also includes an acquisition module 307 and a detection module 308.
[0105] The acquisition module 307 is used to run a health detector to obtain the configuration information of the new master database, including the IP address and port information of the new master database.
[0106] The detection module 308 is used to connect to the new primary database based on configuration information. When it detects that the health detector can perform read and write operations on the new primary database, it determines that the connectivity status of the new primary database is connectable. When it detects that the health detector cannot perform read and write operations on the new primary database, it determines that the connectivity status of the new primary database is not connectable.
[0107] The method provided in this application first obtains multiple metadata information through an extraction module and extracts multiple database cluster status information from the metadata information. Then, a detection module uses multiple processes to poll and probe the database cluster status of multiple database clusters based on the multiple database cluster status information, obtaining the detection results corresponding to each database cluster. Subsequently, a determination module determines the database cluster to be adjusted among the multiple database clusters. The number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers. Finally, a switching module selects a slave database as the new master database in the database cluster to be adjusted and transfers the business currently being processed by the master database in the database cluster to be adjusted to the new master database. By using multiple processes, the database cluster status of multiple database clusters can be polled and probed simultaneously, shortening the overall time of polling and probing. This solves the problem that current database probing consumes a lot of time, making it difficult to detect database faults in a timely manner, resulting in low database switching efficiency.
[0108] In an exemplary embodiment, see Figure 4 The invention also provides a computer device including a bus, a processor, a memory, and a communication interface. It may also include an input / output interface and a display device, wherein the various functional units can communicate with each other via the bus. The memory stores a computer program, and the processor executes the program stored in the memory to perform the database switching method described in the above embodiments.
[0109] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the database switching method.
[0110] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented in hardware or by using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) and includes several instructions to cause a computer device (such as a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0111] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application.
[0112] Those skilled in the art will understand that the modules in the apparatus of the implementation scenario can be distributed within the apparatus of the implementation scenario as described, or they can be located in one or more apparatuses different from this implementation scenario, with corresponding changes. The modules of the above-described implementation scenario can be combined into one module, or they can be further divided into multiple sub-modules.
[0113] The serial numbers in this application are for descriptive purposes only and do not represent the superiority or inferiority of the implementation scenario.
[0114] The above embodiments are merely exemplary embodiments of this application and are not intended to limit this application. The scope of protection of this application is defined by the claims. Those skilled in the art can make various modifications or equivalent substitutions to this application within its substance and scope of protection, and such modifications or equivalent substitutions should also be considered to fall within the scope of protection of this application.
Claims
1. A database switching method, characterized in that, include: The system acquires multiple metadata information and extracts multiple database cluster status information from the multiple metadata information, wherein the multiple metadata information is collected from the multiple database clusters by the anomaly detector when it detects a read operation on multiple database clusters; The cluster identifiers of the multiple database clusters are sequentially assigned to multiple list templates to obtain multiple sub-lists. Based on the status information of the multiple database clusters, a multi-process polling probe is used to detect the status of the multiple database clusters. Each process processes one database cluster in each of the sub-lists. During the polling probe, a database probe request carrying a preset protocol is sent to multiple probe regions corresponding to the multiple database clusters, and the probe results returned by each probe region are received to obtain the probe result corresponding to each database cluster. The probe result corresponding to each database cluster includes the probe success identifier or probe failure identifier returned by each database in the database cluster. Among the plurality of database clusters, a database cluster to be adjusted is determined, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers; In the database cluster to be adjusted, a slave database is selected as the new master database, and the business being processed by the current master database in the database cluster to be adjusted is transferred to the new master database. The database cluster to be adjusted includes a master database and multiple slave databases.
2. The database switching method according to claim 1, characterized in that, Before acquiring multiple metadata information, the method further includes: In response to the polling and probing requests of the multiple database clusters, the anomaly detector is run, and when the anomaly detector detects that it is performing a read operation on the multiple database clusters, metadata information of each database cluster in the multiple database clusters is collected. Multiple sublists are generated based on the multiple database clusters. Each sublist includes multiple database cluster identification information, and each database cluster identification information indicates a database cluster.
3. The database switching method according to claim 2, characterized in that, In response to polling and probing requests for the multiple database clusters, the anomaly detector is run. When the anomaly detector detects that it is performing a read operation on the multiple database clusters, metadata information of each database cluster is collected, including: The anomaly detector is run to perform the following operations on each database in each database cluster: send a database probe request to the database, continuously collect timeout anomaly information, when the timeout anomaly information is collected, continue to send a database probe request to the database, when the timeout anomaly information is not collected, collect the corresponding sub-metadata information of the database, when the database probe request is sent to the database again, continue to collect the timeout anomaly information, when the timeout anomaly information is collected again, continue to send a database probe request to the database within a preset number of times until the corresponding sub-metadata information of the database is collected, wherein the timeout anomaly information is returned by the database in response to the database probe request; Based on the collected sub-metadata information corresponding to each database in each database cluster, the metadata information of each database cluster in the plurality of database clusters is obtained.
4. The database switching method according to claim 2, characterized in that, The generation of multiple sub-lists based on the multiple database clusters includes: Use list comprehension to generate multiple list templates; Based on the number of the multiple database clusters and the number of the multiple list templates, the preset number of database clusters included in each list template is obtained by modulo operation; Based on the preset number of database clusters included in each list template, the identification information of the multiple database clusters is sequentially assigned to the multiple list templates to obtain the multiple sub-lists.
5. The database switching method according to claim 2, characterized in that, Based on the status information of the multiple database clusters, a multi-process polling method is used to probe the status of the multiple database clusters to obtain the probe results corresponding to each database cluster, including: Based on the metadata information of each database cluster, multiple probe areas are determined for each database cluster, and each probe area corresponds to a database in the database cluster; A process is used to poll and probe the status of multiple database clusters indicated by the identification information of multiple database clusters in a sublist. When polling and probing the database clusters, the following operations are performed on each database: sending a database probe request carrying a preset protocol to the probe area corresponding to the database, and receiving a probe result returned by the database in response to the database probe request carrying the preset protocol. Other processes are used to poll and probe the status of the multiple database clusters indicated by the multiple database cluster identification information in the other sublists to obtain other probe results, wherein the other processes are processes other than the one process in the multiple processes.
6. The database switching method according to claim 1, characterized in that, The step of determining the database cluster to be adjusted among the multiple database clusters, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers, includes: The number of successful detection markers and the number of failed detection markers in a database cluster are counted. When the number of successful detection markers is less than the number of failed detection markers, the database cluster is determined to be a database cluster that needs to be adjusted. Continue to count the number of successful probes and the number of failed probes in other database clusters. When the number of successful probes is less than the number of failed probes, determine that the other database cluster is another database cluster to be adjusted. The other database cluster is the database cluster other than the first database cluster among the multiple database clusters.
7. The database switching method according to claim 1, characterized in that, The method further includes: Run a health detector to obtain the configuration information of the new master database, including the IP address and port information of the new master database; Based on the configuration information, the system connects to the new primary database. When the health detector detects that the new primary database can perform read and write operations, the system determines that the new primary database is connected. When the health detector detects that the new primary database cannot perform read and write operations, the system determines that the new primary database is disconnected.
8. A database switching device, characterized in that, include: An extraction module is used to acquire multiple metadata information and extract multiple database cluster status information from the multiple metadata information, wherein the multiple metadata information is collected from the multiple database clusters by the anomaly detector when it detects a read operation on multiple database clusters; The detection module is used to sequentially assign the cluster identifiers of the multiple database clusters to multiple list templates to obtain multiple sub-lists. Based on the status information of the multiple database clusters, a multi-process polling detection is performed on the database cluster status of the multiple database clusters. Each process processes one database cluster in each of the sub-lists. During the polling detection, a database detection request carrying a preset protocol is sent to multiple detection areas corresponding to the multiple database clusters, and the detection results returned by each detection area are received to obtain the detection result corresponding to each database cluster. The detection result corresponding to each database cluster includes a detection success identifier or a detection failure identifier returned by each database in the database cluster. The determination module is used to determine the database cluster to be adjusted among the plurality of database clusters, wherein the number of detection failure markers in the detection results corresponding to the database cluster to be adjusted is greater than the number of detection success markers. The switching module is used to select a slave database as the new master database in the database cluster to be adjusted, and to transfer the business being processed by the current master database in the database cluster to be adjusted to the new master database. The database cluster to be adjusted includes a master database and multiple slave databases.
9. A computer device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
10. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
MySQL fault switching method and device based on sentry mechanism
CN111831489A
Cross-platform database management method and device and electronic equipment
CN113656482A
