CN115344555A - Database switching method and device, electronic equipment and storage medium - Google Patents

Database switching method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN115344555A
CN115344555A CN202210968279.7A CN202210968279A CN115344555A CN 115344555 A CN115344555 A CN 115344555A CN 202210968279 A CN202210968279 A CN 202210968279A CN 115344555 A CN115344555 A CN 115344555A
Authority
CN
China
Prior art keywords
database
virtual
cluster
target
databases
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210968279.7A
Other languages
Chinese (zh)
Inventor
李缃烨
翟菁
张培驹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210968279.7A priority Critical patent/CN115344555A/en
Publication of CN115344555A publication Critical patent/CN115344555A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0811Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity

Abstract

The invention discloses a database switching method and device, electronic equipment and a storage medium, and relates to the field of big data, wherein the method comprises the following steps: responding to an abnormal detection request for a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and detecting the connectivity of virtual IP addresses of the plurality of databases through a preset domain name detection equipment cluster; under the condition that the availability abnormality of the master database is detected, selecting a target slave database from a plurality of slave databases as a switched master database based on a master database election strategy; unbinding the first virtual IP address of the main database, and binding the second virtual IP address of the switched main database; and determining that the database switching is finished under the condition that the second virtual IP address of the switched main database is connected and other virtual IP addresses of the target database cluster are not connected.

Description

Database switching method and device, electronic equipment and storage medium
Technical Field
The invention relates to the field of big data, in particular to a database switching method and device, electronic equipment and a storage medium.
Background
At present, according to the deployment and service mode of a current database, the database switching process is complex, manual intervention is needed, faults are located, whether the database switching needs to be carried out or not is judged, a mode of manually triggering the database switching is adopted, and due to the fact that the size of the database is large, rapid switching cannot be achieved under the condition of large-scale faults, service recovery is carried out, and emergency timeliness cannot meet the guarantee requirements of system availability and service continuity.
In the related art, in order to reduce the time of switching the domain name interface in the database switching process, the same virtual IP address is adopted in the same database cluster, so that the risk that the data is prone to split in the database switching process under the scene that the main database fails is introduced, and meanwhile, the problems that the isolation cannot be thoroughly carried out on an infrastructure fault domain and the high availability of an infrastructure cannot play a role to the maximum degree are also introduced.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the invention provides a database switching method and device, electronic equipment and a storage medium, and aims to at least solve the technical problems that in the related art, master-slave database switching needs to be triggered manually, and data split is easy to occur in the switching process.
According to an aspect of an embodiment of the present invention, a method for switching a database is provided, including: responding an abnormal detection request for a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and simultaneously detecting connectivity of virtual IP addresses of the plurality of databases in the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster comprises a main database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used for providing service interfaces for service request terminals; under the condition that the availability of the master database is detected to be abnormal, selecting a target slave database from the plurality of slave databases based on a master database election strategy, and taking the target slave database as a switched master database; unbinding the first virtual IP address of the master database, and binding the second virtual IP address of the switched master database; and determining that the database switching is completed under the condition that the second virtual IP address of the switched main database is detected to be communicated and other virtual IP addresses of the target database cluster are not communicated.
Optionally, before detecting connectivity of virtual IP addresses of multiple databases in the target database cluster by presetting the domain name detection device cluster, the method includes: and determining the detection frequency of the preset domain name detection equipment cluster based on a database switching time threshold and a detection frequency threshold of a database, wherein the database switching time threshold is recovery time for switching the database.
Optionally, the step of detecting connectivity of virtual IP addresses of multiple databases in the target database cluster by presetting the domain name detection device cluster includes: step 1, selecting a database from the target database cluster as a target database; step 2, detecting connectivity of a virtual IP address of the target database through a preset domain name detection device cluster, and determining a target detection result, where the preset domain name detection device cluster includes a plurality of domain name detection devices, and the target detection result at least includes: performing connectivity detection on the target database by adopting a plurality of domain name detection devices in the preset domain name detection device cluster, wherein the result of the connectivity detection is the number of the passing domain name detection devices; step 3, when the target detection result shows that the number of passed connectivity detections is greater than a preset threshold value, the target database shows that the virtual IP address connectivity detections of the target database pass; and (4) taking the other databases of the target database cluster as the target databases in sequence, and executing the step (2) and the step (3) to determine the connectivity of the virtual IP address of each database of the target database cluster.
Optionally, the step of unbinding the first virtual IP address of the master database and binding the second virtual IP address of the switched master database further includes: unbinding a first virtual IP address of the main database, and setting the read-write state of the main database to be a read-only state; and binding the second virtual IP address of the switched main database, and setting the read-write state of the switched main database as the read-write state.
Optionally, after performing availability detection on the multiple databases of the target database cluster by using a preset availability detection policy, the method further includes: and in the case that the target slave database in the target database cluster is unavailable, deleting the target slave database node in the target database cluster and updating the number of available databases in the target database cluster.
Optionally, before responding to the anomaly detection request to the target database cluster, the method includes: and configuring the domain name of the target database cluster through a preset domain name detection equipment cluster, and configuring the virtual IP address of each database in the target database cluster.
Optionally, after detecting connectivity of virtual IP addresses of a plurality of databases in the target database cluster through a preset domain name detection device cluster, the method further includes: under the condition that the detection result is that the virtual IP addresses of all the databases in the target database cluster are not communicated, the target database cluster does not provide service for the service request end, wherein the detection result is the connectivity detection result of the virtual IP addresses; under the condition that the detection result is that the number of databases communicated by the virtual IP addresses in the target database cluster is greater than 1, the target database cluster does not provide service for the service request end; and returning the virtual IP address of the main database and providing service for a service request end based on the virtual IP address of the main database under the condition that the detection result is that the virtual IP addresses of the main database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated.
According to another aspect of the embodiments of the present invention, there is further provided a database switching apparatus, including: the system comprises a first processing unit, a second processing unit and a third processing unit, wherein the first processing unit is used for responding to an abnormal detection request of a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and simultaneously detecting the connectivity of virtual IP addresses of the databases in the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster comprises a master database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used for providing service interfaces for service request terminals; a second processing unit, configured to, in a case that the availability of the master database is detected to be abnormal, select a target slave database from the plurality of slave databases based on a master database election policy, and use the target slave database as a switched master database; the third processing unit is used for unbinding the first virtual IP address of the main database and binding the second virtual IP address of the switched main database; and the determining unit is used for determining that the database switching is finished under the condition that the second virtual IP addresses of the switched main database are connected and other virtual IP addresses of the target database cluster are not connected.
Optionally, the switching device of the database further includes: the determining unit is configured to determine, before detecting connectivity of virtual IP addresses of multiple databases in the target database cluster through a preset domain name detection device cluster, a detection frequency of the preset domain name detection device cluster based on a database switching time threshold and a detection frequency threshold of the databases, where the database switching time threshold is recovery time for switching the databases.
Optionally, the first processing unit comprises: a selecting subunit, which selects one database in the target database cluster as a target database; determining a subunit, detecting connectivity of a virtual IP address of the target database through a preset domain name detection device cluster, and determining a target detection result, where the preset domain name detection device cluster includes a plurality of domain name detection devices, and the target detection result at least includes: performing connectivity detection on the target database by adopting a plurality of domain name detection devices in the preset domain name detection device cluster, wherein the result of the connectivity detection is the number of the passed domain name detection devices; the first processing subunit is used for indicating that the virtual IP address connectivity detection of the target database passes under the condition that the target detection result indicates that the number of the passed connectivity detection is greater than a preset threshold value; and the second processing subunit is used for sequentially taking the rest databases of the target database cluster as the target databases to determine the connectivity of the virtual IP address of each database of the target database cluster.
Optionally, the third processing unit comprises: the third processing subunit is configured to unbind the first virtual IP address of the main database, and set the read-write state of the main database to a read-only state; and the fourth processing subunit is configured to bind the second virtual IP address of the switched main database, and set the read-write state of the switched main database to the read-write state.
Optionally, the switching device of the database further includes: and the updating unit is used for deleting the target slave database node in the target database cluster and updating the number of available databases in the target database cluster when the target slave database in the target database cluster is unavailable after availability detection is carried out on the plurality of databases in the target database cluster through a preset availability detection strategy.
Optionally, the switching device of the database further includes: the configuration unit is used for configuring the domain name of the target database cluster through a preset domain name detection equipment cluster before responding to the abnormal detection request of the target database cluster, and configuring the virtual IP address of each database in the target database cluster.
Optionally, the switching device of the database further includes: the fourth processing unit is configured to, after detecting connectivity of virtual IP addresses of multiple databases in the target database cluster through a preset domain name detection device cluster, under a condition that a detection result indicates that the virtual IP addresses of all databases in the target database cluster are not connected, the target database cluster does not provide service for the service request end, where the detection result is a connectivity detection result of the virtual IP addresses; the fifth processing unit is used for not providing service for the service request end by the target database cluster under the condition that the detection result is that the number of databases communicated by the virtual IP addresses in the target database cluster is greater than 1; and the sixth processing unit is used for returning the virtual IP address of the main database and providing service for the service request end based on the virtual IP address of the main database when the detection result indicates that the virtual IP addresses of the main database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated.
In the invention, in response to an abnormal detection request for a target database cluster, firstly, availability detection is carried out on a plurality of databases of the target database cluster through a preset availability detection strategy, and meanwhile, connectivity of virtual IP addresses of the databases in the target database cluster is detected through a preset domain name detection equipment cluster, wherein the target database cluster comprises a main database and a plurality of slave databases, each database corresponds to a unique virtual IP address, the virtual IP addresses are used for providing service interfaces for a service request terminal, then, under the condition that the abnormal availability of the main database is detected, a target slave database is selected from the plurality of slave databases based on a main database selection strategy, the target slave database is used as a switched main database, then, a first virtual IP address of the main database is released, a second virtual IP address of the switched main database is bound, and finally, under the condition that the second virtual IP address of the switched main database is connected and other virtual IP addresses of the switched main database are not connected, the problem that the switching of the databases needs to be manually triggered in the related database and the master database is easy to be split in the process of data base switching is solved.
In the invention, the availability of the main database in the database cluster is detected through an availability detection strategy to determine whether to switch the databases, thereby improving the switching efficiency of the databases, and meanwhile, the connectivity of the unique virtual IP address of each database is detected through the domain name detection equipment cluster to determine whether the target database cluster provides service to the outside, thereby avoiding the condition that the database is switched by using the same virtual IP address to generate data split and double writing, and further achieving the technical effect of reducing the data split risk.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the invention without limiting the invention. In the drawings:
fig. 1 is a flow chart of an alternative database handoff method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of an alternative database switching apparatus according to an embodiment of the present invention;
fig. 3 is a block diagram of a hardware structure of an electronic device (or a mobile device) according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in other sequences than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that the database switching method and apparatus in the present disclosure may be used in a situation where a master database and a slave database are switched in a big data field, and may also be used in any field other than the big data field in a situation where a master database is abnormal and a master database is switched, and the application fields of the database switching method and apparatus in the present disclosure are not limited.
It should be noted that relevant information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for presentation, analyzed data, etc.) referred to in the present disclosure are information and data that are authorized by the user or sufficiently authorized by various parties. For example, an interface is provided between the system and the relevant user or institution, and before obtaining the relevant information, an obtaining request needs to be sent to the user or institution through the interface, and after receiving the consent information fed back by the user or institution, the relevant information needs to be obtained.
The invention can be applied to database clusters for storing data of various software products, control systems and clients (including but not limited to mobile clients, PCs and the like) of various financial institutions, the software products are taken as an example for schematic illustration, and the data of business contents (including but not limited to business functions of transferring accounts, managing money, fund, paying fees, checking accounts, advertising, recommending and the like) of the financial institutions can be stored through the database cluster for storing the data of the mobile clients.
In the invention, the availability of a main database in a database cluster is detected through an availability detection strategy to determine whether to switch the databases, and meanwhile, the connectivity of a unique virtual IP address of each database is detected through a domain name detection equipment cluster to determine whether a target database cluster provides services to the outside, and whether the database cluster can provide the services to the outside is judged according to the detection result of the connectivity of the virtual IP address, thereby realizing the technical effects of improving the switching efficiency of the databases and reducing the brain crack risk of the data.
The present invention will be described in detail with reference to examples.
Example one
In accordance with an embodiment of the present invention, there is provided an alternative method embodiment for database switching, it being noted that the steps illustrated in the flowchart of the figure may be performed in a computer system such as a set of computer-executable instructions, and that although a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
Fig. 1 is a flowchart of an alternative database switching method according to an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step S101, responding to an abnormal detection request for a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and simultaneously detecting connectivity of virtual IP addresses of the plurality of databases in the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster comprises a main database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used for providing service interfaces for service request terminals.
The target database cluster may include a master database and a plurality of slave databases, where the databases may be MySql data and SQLServer databases, and the type of the database is not limited herein in this embodiment.
The preset availability detection strategy can be an availability detection strategy of a database availability management and control system, and can also be used for detecting the availability of the database through a high-availability component of the database, the preset availability detection strategy can be used for detecting the availability of a plurality of databases in a database cluster, master database switching can be carried out when the master database is detected to be unavailable, slave databases can be marked when the slave databases are detected to be unavailable, or unavailable slave database nodes are removed, and the unavailable slave databases are prevented from being switched to master databases.
In order to solve the problem that the same virtual IP address is adopted by a database cluster in the related technology, the same virtual IP address is used by two databases in the database switching process, and data split and double write are easy to occur, each database in a target database cluster can be configured with a unique virtual IP address, the connectivity of the virtual IP addresses of the databases is detected, and meanwhile, whether the main database can provide services for the outside or not can be represented through the VIP connectivity state of the main database, so that the high availability of the database cluster is ensured, and the technical effect of improving the data processing quality of the database cluster is realized.
And step S102, under the condition that the availability of the master database is detected to be abnormal, selecting one target slave database from a plurality of slave databases based on the master database selection strategy, and taking the target slave database as a switched master database.
In order to ensure the availability of the database cluster, in the case of detecting the abnormal availability of the master database, a target slave database can be selected from a plurality of slave databases based on a master database election strategy, and the target slave database is used as a switched master database, so that the aim of switching the unavailable master database is fulfilled.
And step S103, unbinding the first virtual IP address of the master database and binding the second virtual IP address of the switched master database.
The method realizes the interruption of external service in the database switching process by virtually unbinding the first virtual IP address of the main database and binding the second virtual IP address of the switched main database, achieves the aim of intercepting transactions, and can also avoid the brain split double-write risk that two database nodes are bound simultaneously on one virtual IP address.
And step S104, determining that the database switching is finished under the condition that the second virtual IP address of the switched main database is connected and other virtual IP addresses of the target database cluster are not connected.
By detecting the connectivity state of the virtual IP address of the switched database cluster, under the condition that the second virtual IP address of the switched main database is detected to be communicated and other virtual IP addresses of the target database cluster are not communicated, the completion of the switching of the database is determined, and the target database can provide services to the outside, so that the aim of intercepting transactions in the database switching process is fulfilled, the stable switching of the database is realized, and the technical effect of ensuring that the database cluster provides accurate services is achieved.
In the above steps, the availability of the master database in the database cluster is detected through the availability detection strategy to determine whether to perform database switching, so that the efficiency of database switching is improved, and meanwhile, the connectivity of the unique virtual IP address of each database is detected through the domain name detection equipment cluster to determine whether the target database cluster provides services to the outside, so that the conditions that the database switching is performed by using the same virtual IP address, and the data split is written in a double way are avoided, and the technical effect of reducing the data split risk is achieved.
It should be noted that the target database cluster in this embodiment may include a plurality of databases.
Examples of the present invention are further illustrated below.
In order to improve the connectivity detection efficiency of the virtual IP addresses of the databases, before detecting the connectivity of the virtual IP addresses of a plurality of databases in a target database cluster by presetting a domain name detection device cluster, in the embodiment of the present application, the following steps are defined: determining the detection frequency of a preset domain name detection equipment cluster based on a database switching time threshold and a detection frequency threshold of a database, wherein the database switching time threshold is recovery time for switching the database.
By presetting the domain name detection equipment cluster, before detecting the connectivity of the virtual IP addresses of the multiple databases in the target database cluster, the detection frequency of detecting the connectivity of the virtual IP addresses can be determined, and the detection comment can be determined by comprehensively considering the recovery time of switching the databases and the detection frequency threshold which can be borne by the databases.
It should be noted that the detection frequency should be smaller than the recovery time for switching the database and the detection frequency threshold that can be borne by the database, the recovery time for switching the database may be an RTO requirement (that is, the recovery time target, the time length that the database is allowed to be interrupted), and the detection frequency should be close to the recovery time for switching the database and the detection frequency threshold that can be borne by the database, so as to achieve the technical effect of improving the connectivity detection efficiency of the virtual IP address of the database.
In order to improve the accuracy of detecting the connectivity of the target database cluster, in the embodiment of the present application, the step of detecting the connectivity of the virtual IP addresses of the multiple databases in the target database cluster by using the preset domain name detection device cluster is further defined as follows: step 1, selecting one database from a target database cluster as a target database; step 2, detecting connectivity of a virtual IP address of a target database through a preset domain name detection device cluster, and determining a target detection result, wherein the preset domain name detection device cluster comprises a plurality of domain name detection devices, and the target detection result at least comprises: performing connectivity detection on the target database by adopting a plurality of domain name detection devices in a preset domain name detection device cluster, wherein the result of the connectivity detection is the number of the passed domain name detection devices; step 3, when the target detection result shows that the number of the passed connectivity detections is larger than a preset threshold value, the passing connectivity detections of the virtual IP addresses of the target database are shown; and (3) sequentially taking the rest databases of the target database cluster as target databases, and executing the step 2 and the step 3 to determine the connectivity of the virtual IP address of each database of the target database cluster.
In order to deal with the risk of wrong connectivity detection results caused by the faults of the domain name detection equipment, the connectivity of the virtual IP addresses of the database can be detected through a preset domain name detection equipment cluster, and after the connectivity of the virtual IP addresses of the database is detected by the domain name detection equipment with a preset threshold number, the virtual IP address connectivity of the database can be determined to pass the detection. The method avoids the condition of 'one talk around' of a single device, avoids the risk of wrong analysis results caused by wrong connectivity detection results due to the fault of the domain name detection device, and achieves the technical effect of improving the accuracy of virtual IP address connectivity detection.
The log of the connectivity state change of the database can be recorded by the domain name detection equipment cluster and aggregated with the database operation monitoring view, so that the time efficiency of fault finding and positioning is improved, wherein the monitoring view of the database can monitor the operation state of each database node in the database cluster.
In order to ensure high availability of a target database cluster, after availability detection is performed on a plurality of databases of the target database cluster through a preset availability detection policy, in the embodiment of the application, the following steps are defined: and in the case that the target slave database in the target database cluster is unavailable, deleting the target slave database node in the target database cluster, and updating the number of available databases in the target database cluster.
In a target database cluster, when the target slave database is detected to run abnormally, availability handling can be started through an availability management and control system of the database cluster, the abnormality in the unit is kicked off from the database node, and the unit availability threshold value (namely the number of available databases) is adjusted.
In order to ensure that the target database cluster provides stable and effective service for the service request end, after detecting connectivity of virtual IP addresses of a plurality of databases in the target database cluster by presetting a domain name detection device cluster, in this embodiment, the following steps are further defined: under the condition that the detection result is that the virtual IP addresses of all databases in the target database cluster are not communicated, the target database cluster does not provide service for the service request end, wherein the detection result is the communication detection result of the virtual IP addresses; under the condition that the detection result is that the number of the databases communicated by the virtual IP addresses in the target database cluster is larger than 1, the target database cluster does not provide service for the service request end; and returning the virtual IP address of the master database under the condition that the detection result is that the virtual IP addresses of the master database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated, and providing service for the service request end based on the virtual IP address of the master database.
The available state of the database cluster is indicated through the connectivity state of the virtual IP addresses of the databases, the target database cluster does not provide service to the outside under the condition that the virtual IP addresses of all the databases in the target database cluster are not communicated, the target database cluster does not provide service to the service request end, as the database cluster only provides service to the outside through the virtual IP address of the main database under the normal operation state, the target database cluster also does not provide service to the service request end under the condition that the detection result of the connectivity detection of the virtual IP addresses is that the number of the databases communicated through the virtual IP addresses in the target database cluster is larger than 1, and the virtual IP address of the main database can be returned only when the detection result is that the virtual IP addresses of the main database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated, and the operation state of the target database can be normal, and the service request end is provided with service based on the virtual IP address of the main database.
For example, in the case of health check (corresponding to virtual IP address connectivity detection) full down (corresponding to target database cluster virtual IP address connectivity detection is not connected), a specific policy needs to be configured on the domain name device, and when the health check of the server (corresponding to the database) is not passed, no return is made, so as to avoid the intelligent domain name device (corresponding to the preset domain name detection device cluster) from mistakenly selecting addresses. When the health check of a plurality of database members passes, a user-defined automatic script can be configured on the domain name equipment, and the logic is set to be that when the number of the members in the Active (connected) state is more than 1, no return is made, so that the intelligent domain name equipment is prevented from misselecting addresses.
Whether the target database cluster is normally communicated or not is judged through the connectivity state of the virtual IP address of the virtual database, whether the service can be provided for the service request end or not is judged, and the technical effect of improving the database cluster availability detection efficiency is achieved.
In order to ensure the accuracy of the read-write state of the target database cluster, in this embodiment, the step of unbinding the first virtual IP address of the master database and binding the second virtual IP address of the switched master database is further defined as follows: unbinding a first virtual IP address of a main database, and setting a read-write state of the main database to be a read-only state; and binding the second virtual IP address of the switched main database, and setting the read-write state of the switched main database as the read-write state.
Taking the MySql database as an example, a mode of unbinding the first virtual IP address of the master database and binding the second virtual IP address of the switched master database is schematically described below, in the process that the MySql database availability control system controls the switching of MySql data, after the master-slave election is completed, VIP unbinding can be performed on the original master database, and the VIP unbinding is set to be in a read-only state, and VIP binding operation is performed on the new master database, and the VIP unbinding is set to be in a read-write state.
It should be noted that in this embodiment, connectivity check on the VIP is necessary, but check on the read-write state of the database may not be necessary, and the master-slave arbitration election process of the database may ensure that the read-write state is changed first, and then a new main bank VIP is bound, thereby achieving the technical effect of improving the high availability of the database.
In an optional implementation manner, the database read-write state is guaranteed by the DMP, and the intelligent domain name (preset domain name detection device cluster) can not check the read-write state any more, thereby achieving the technical effect of improving the database switching efficiency.
In order to avoid the split brain double-write condition in the target database cluster during the database switching process, before responding to the abnormality detection request for the target database cluster, in this embodiment, the following steps are further defined: and configuring the domain name of a target database cluster through a preset domain name detection equipment cluster, and configuring the virtual IP address of each database in the target database cluster.
Through the virtual IP address of each database in the target database cluster, unique VIP is preset in each database node of the target database cluster, the risk of split brain and double write of one virtual IP address on two nodes is reduced in the database switching process, and the technical effect of providing high-availability switching of the databases is achieved.
By the embodiment, the switching timeliness of the database can be improved, the time consumption for simultaneously switching large-scale databases is greatly reduced, the occurrence of split brain double-writing in the switching process of the database is avoided, the operation influence on the distributed database caused by infrastructure faults is more perfectly, more fully and more efficiently handled by the database, and the continuous and stable operation of the service information system of the database cluster is guaranteed.
The invention is described below in connection with an alternative embodiment.
Example two
The present embodiment provides an alternative database switching apparatus, as shown in fig. 2, the switching apparatus includes a first processing unit 21, a second processing unit 22, a third processing unit 23, and a determining unit 24, wherein,
the first processing unit 21 is configured to perform availability check on a plurality of databases of the target database cluster through a preset availability check policy in response to an anomaly check request for the target database cluster, and simultaneously check connectivity of virtual IP addresses of the plurality of databases in the target database cluster through a preset domain name check device cluster, where the target database cluster includes a master database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used to provide a service interface for a service requester.
And a second processing unit 22, configured to, in a case where an abnormal availability of the master database is detected, select one target slave database from the plurality of slave databases based on the master database election policy, and use the target slave database as the switched master database.
The third processing unit 23 is configured to unbind the first virtual IP address of the master database, and bind the second virtual IP address of the switched master database.
And a determining unit 24, configured to determine that database switching is completed when it is detected that the second virtual IP address of the switched master database is connected and other virtual IP addresses of the target database cluster are not connected.
The above-mentioned switching apparatus for databases may first respond to an abnormal detection request for a target database cluster through a first processing unit 21, detect availability of a plurality of databases of the target database cluster through a preset availability detection policy, and detect connectivity of virtual IP addresses of the plurality of databases of the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster includes a master database and a plurality of slave databases, each database corresponds to a unique virtual IP address, the virtual IP addresses are used for providing a service interface to a service request end, when an abnormal availability of the master database is detected, a target slave database is elected from the plurality of slave databases through a second processing unit 22 based on the master database election policy, the target slave database is used as a switched master database, then the first virtual IP address of the master database is released through a third processing unit 23, the second virtual IP address of the switched master database is determined through a determination unit 24, when the second virtual IP address of the switched master database is detected to be connected, and other virtual IP addresses of the target database cluster are not connected, thereby easily determining technical problems of data binding in the master database and data binding of the master database. In the invention, the availability of the main database in the database cluster is detected through an availability detection strategy to determine whether to switch the databases, thereby improving the switching efficiency of the databases, and meanwhile, the connectivity of the unique virtual IP address of each database is detected through the domain name detection equipment cluster to determine whether the target database cluster provides service to the outside, thereby avoiding the condition that the database is switched by using the same virtual IP address to generate data split and double writing, and further achieving the technical effect of reducing the data split risk.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the database switching apparatus further includes: the determining unit is used for determining the detection frequency of the preset domain name detection equipment cluster based on a database switching time threshold and a detection frequency threshold of a database before detecting the connectivity of virtual IP addresses of a plurality of databases in a target database cluster through the preset domain name detection equipment cluster, wherein the database switching time threshold is the recovery time for switching the databases.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the first processing unit includes: the selecting subunit selects one database from the target database cluster as a target database; determining a subunit, detecting connectivity of a virtual IP address of a target database by presetting a domain name detection device cluster, and determining a target detection result, wherein the preset domain name detection device cluster includes a plurality of domain name detection devices, and the target detection result at least includes: performing connectivity detection on the target database by adopting a plurality of domain name detection devices in a preset domain name detection device cluster, wherein the result of the connectivity detection is the number of the passing domain name detection devices; the first processing subunit is used for indicating that the connectivity detection of the virtual IP address of the target database passes under the condition that the target detection result indicates that the number of the passed connectivity detection is greater than a preset threshold value; and the second processing subunit is used for sequentially taking the rest databases of the target database cluster as target databases to determine the connectivity of the virtual IP address of each database of the target database cluster.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the third processing unit includes: the third processing subunit is used for unbinding the first virtual IP address of the main database and setting the read-write state of the main database to be a read-only state; and the fourth processing subunit is used for binding the second virtual IP address of the switched main database and setting the read-write state of the switched main database as the read-write state.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the database switching apparatus further includes: and the updating unit is used for deleting the target slave database nodes in the target database cluster and updating the number of available databases in the target database cluster under the condition that the target slave database in the target database cluster is unavailable after the availability of the plurality of databases in the target database cluster is detected through a preset availability detection strategy.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the database switching apparatus further includes: and the configuration unit is used for configuring the domain name of the target database cluster through the preset domain name detection equipment cluster and configuring the virtual IP address of each database in the target database cluster before responding to the abnormal detection request of the target database cluster.
Optionally, in the database switching apparatus according to the second embodiment of the present application, the database switching apparatus further includes: the fourth processing unit is used for detecting the connectivity of the virtual IP addresses of a plurality of databases in the target database cluster through the preset domain name detection equipment cluster, and under the condition that the detection result is that the virtual IP addresses of all the databases in the target database cluster are not communicated, the target database cluster does not provide service for the service request end, wherein the detection result is the connectivity detection result of the virtual IP addresses; the fifth processing unit is used for not providing service for the service request end by the target database cluster under the condition that the detection result is that the number of the databases communicated by the virtual IP addresses in the target database cluster is larger than 1; and the sixth processing unit is used for returning the virtual IP address of the main database and providing service for the service request end based on the virtual IP address of the main database when the detection result is that the virtual IP addresses of the main database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated.
The above-mentioned switching device for the database may further include a processor and a memory, and the above-mentioned first processing unit 21, second processing unit 22, third processing unit 23, determining unit 24, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to implement the corresponding functions.
The processor comprises a kernel, and the kernel calls the corresponding program unit from the memory. The kernel can be set to be one or more, the kernel parameters are adjusted to detect the availability of a main database in the database cluster through an availability detection strategy to determine whether to switch the databases, and meanwhile, the domain name detection equipment cluster is used to detect the connectivity of the unique virtual IP address of each database to determine whether the target database cluster provides services for the outside.
The memory may include volatile memory in a computer readable medium, random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including: a processor; and a memory for storing executable instructions for the processor; wherein the processor is configured to perform the database switching method of any one of the above via execution of the executable instructions.
According to another aspect of the embodiments of the present invention, a computer-readable storage medium is further provided, where the computer-readable storage medium includes a stored computer program, and when the computer program runs, a device in which the computer-readable storage medium is located is controlled to execute any one of the above methods for switching databases.
Fig. 3 is a block diagram of a hardware structure of an electronic device (or a mobile device) according to an embodiment of the present invention. As shown in fig. 3, the electronic device may include one or more (shown as 302a, 302b, \8230;, 302 n) processors 302 (processor 302 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), memory 304 for storing data. Besides, the method can also comprise the following steps: a display, an input/output interface (I/O interface), a Universal Serial Bus (USB) port (which may be included as one of the ports of the I/O interface), a network interface, a keyboard, a power supply, and/or a camera. It will be understood by those skilled in the art that the structure shown in fig. 3 is only an illustration and is not intended to limit the structure of the electronic device. For example, the electronic device may also include more or fewer components than shown in FIG. 3, or have a different configuration than shown in FIG. 3.
The above-mentioned serial numbers of the embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments.
In the above embodiments of the present invention, the description of each embodiment has its own emphasis, and reference may be made to the related description of other embodiments for parts that are not described in detail in a certain embodiment.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention, which is substantially or partly contributed by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk, and various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and amendments can be made without departing from the principle of the present invention, and these modifications and amendments should also be considered as the protection scope of the present invention.

Claims (10)

1. A database switching method is characterized by comprising the following steps:
responding an abnormal detection request for a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and simultaneously detecting the connectivity of virtual IP addresses of the plurality of databases in the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster comprises a main database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used for providing service interfaces for service request terminals;
under the condition that the availability of the master database is detected to be abnormal, selecting one target slave database from the plurality of slave databases based on a master database election strategy, and taking the target slave database as a switched master database;
unbinding the first virtual IP address of the master database, and binding the second virtual IP address of the switched master database;
and determining that the database switching is completed under the condition that the second virtual IP address of the switched main database is detected to be communicated and other virtual IP addresses of the target database cluster are not communicated.
2. The method for switching databases according to claim 1, wherein before detecting connectivity of virtual IP addresses of multiple databases in the target database cluster through a preset domain name detection device cluster, the method includes:
and determining the detection frequency of the preset domain name detection equipment cluster based on a database switching time threshold and a detection frequency threshold of a database, wherein the database switching time threshold is recovery time for switching the database.
3. The database switching method according to claim 1, wherein the step of detecting connectivity of virtual IP addresses of a plurality of databases in the target database cluster through a preset domain name detection device cluster comprises:
step 1, selecting a database from the target database cluster as a target database;
step 2, detecting connectivity of the virtual IP address of the target database through a preset domain name detection device cluster, and determining a target detection result, where the preset domain name detection device cluster includes multiple domain name detection devices, and the target detection result at least includes: performing connectivity detection on the target database by adopting a plurality of domain name detection devices in the preset domain name detection device cluster, wherein the result of the connectivity detection is the number of the passing domain name detection devices;
step 3, when the target detection result shows that the number of passed connectivity detections is greater than a preset threshold value, the target database shows that the virtual IP address connectivity detections of the target database pass;
and (3) sequentially taking the other databases of the target database cluster as the target databases, and executing the step (2) and the step (3) to determine the connectivity of the virtual IP address of each database of the target database cluster.
4. The database switching method according to claim 1, wherein the step of unbinding the first virtual IP address of the master database and binding the second virtual IP address of the switched master database further comprises:
unbinding the first virtual IP address of the main database, and setting the read-write state of the main database to be a read-only state;
and binding the second virtual IP address of the switched main database, and setting the read-write state of the switched main database as the read-write state.
5. The database switching method according to claim 1, wherein after performing the availability check on the plurality of databases of the target database cluster by using a preset availability check policy, the method further comprises:
and in the case that the target slave database in the target database cluster is unavailable, deleting the target slave database node in the target database cluster and updating the number of available databases in the target database cluster.
6. The database switching method according to claim 3, wherein before responding to the anomaly detection request to the target database cluster, the method comprises:
and configuring the domain name of the target database cluster through a preset domain name detection equipment cluster, and configuring the virtual IP address of each database in the target database cluster.
7. The database switching method according to claim 1, wherein after detecting connectivity of virtual IP addresses of a plurality of databases in the target database cluster through a preset domain name detection device cluster, the method further comprises:
under the condition that the detection result is that the virtual IP addresses of all the databases in the target database cluster are not communicated, the target database cluster does not provide service for a service request end, wherein the detection result is the detection result of the connectivity of the virtual IP addresses;
under the condition that the detection result is that the number of databases communicated by the virtual IP addresses in the target database cluster is greater than 1, the target database cluster does not provide service for the service request end;
and returning the virtual IP address of the master database under the condition that the detection result is that the virtual IP addresses of the master database of the target database cluster are communicated and the virtual IP addresses of other slave databases are not communicated, and providing service for the service request end based on the virtual IP address of the master database.
8. A database switching apparatus, comprising:
the system comprises a first processing unit, a second processing unit and a third processing unit, wherein the first processing unit is used for responding to an abnormal detection request of a target database cluster, carrying out availability detection on a plurality of databases of the target database cluster through a preset availability detection strategy, and simultaneously detecting the connectivity of virtual IP addresses of the databases in the target database cluster through a preset domain name detection equipment cluster, wherein the target database cluster comprises a master database and a plurality of slave databases, each database corresponds to a unique virtual IP address, and the virtual IP addresses are used for providing service interfaces for service request terminals;
a second processing unit, configured to, in a case that the availability of the master database is detected to be abnormal, select a target slave database from the plurality of slave databases based on a master database election policy, and use the target slave database as a switched master database;
the third processing unit is used for unbinding the first virtual IP address of the main database and binding the second virtual IP address of the switched main database;
and the determining unit is used for determining that the database switching is finished under the condition that the second virtual IP address of the switched main database is connected and other virtual IP addresses of the target database cluster are not connected.
9. A computer-readable storage medium, comprising a stored computer program, wherein when the computer program runs, the computer-readable storage medium is controlled to execute the database switching method according to any one of claims 1 to 7.
10. An electronic device comprising one or more processors and memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the database switching method of any one of claims 1 to 7.
CN202210968279.7A 2022-08-12 2022-08-12 Database switching method and device, electronic equipment and storage medium Pending CN115344555A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210968279.7A CN115344555A (en) 2022-08-12 2022-08-12 Database switching method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210968279.7A CN115344555A (en) 2022-08-12 2022-08-12 Database switching method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115344555A true CN115344555A (en) 2022-11-15

Family

ID=83951578

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210968279.7A Pending CN115344555A (en) 2022-08-12 2022-08-12 Database switching method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115344555A (en)

Similar Documents

Publication Publication Date Title
US10261853B1 (en) Dynamic replication error retry and recovery
US11194679B2 (en) Method and apparatus for redundancy in active-active cluster system
CN1770707B (en) Apparatus and method for quorum-based power-down of unresponsive servers in a computer cluster
CN110807064B (en) Data recovery device in RAC distributed database cluster system
US9973382B2 (en) Hitless upgrade for network control applications
US9798639B2 (en) Failover system and method replicating client message to backup server from primary server
CN108418859B (en) Method and device for writing data
CN114265753A (en) Management method and management system of message queue and electronic equipment
CN113312153A (en) Cluster deployment method and device, electronic equipment and storage medium
CN111181774A (en) High-availability method, system, terminal and storage medium for MapReduce task
CN111475104A (en) Storage device data online migration method, system, terminal and storage medium
CN112181723A (en) Financial disaster recovery method and device, storage medium and electronic equipment
CN108733466A (en) Restart the method, apparatus and equipment of the application system example in distributed system
JP2000148683A (en) On-line system, data transmission managing method for the on-line system, and recording medium where program for managing data transmission is recorded
CN109298977A (en) A kind of virtual machine business quick recovery method, system, device and storage medium
Golla et al. T4: A highly threaded server-on-a-chip with native support for heterogeneous computing
CN112527480A (en) End-to-end double-activity method, device, equipment and storage medium
US20230214153A1 (en) Memory device forensics and preparation
CN115344555A (en) Database switching method and device, electronic equipment and storage medium
US20190124145A1 (en) Method and apparatus for availability management
CN115237889A (en) Database switching method and device, storage medium and computer equipment
CN115686951A (en) Fault processing method and device for database server
CN114238324A (en) Checking method and device for host station, electronic equipment and storage medium
CN110413686B (en) Data writing method, device, equipment and storage medium
CN110502460B (en) Data processing method and node

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination