CN112015595B - Master-slave database switching method, computing device and storage medium - Google Patents

Master-slave database switching method, computing device and storage medium Download PDF

Info

Publication number
CN112015595B
CN112015595B CN202010887335.5A CN202010887335A CN112015595B CN 112015595 B CN112015595 B CN 112015595B CN 202010887335 A CN202010887335 A CN 202010887335A CN 112015595 B CN112015595 B CN 112015595B
Authority
CN
China
Prior art keywords
database
master
slave
data
master database
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.)
Active
Application number
CN202010887335.5A
Other languages
Chinese (zh)
Other versions
CN112015595A (en
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.)
Ireader Technology Co Ltd
Original Assignee
Ireader Technology Co Ltd
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 Ireader Technology Co Ltd filed Critical Ireader Technology Co Ltd
Priority to CN202010887335.5A priority Critical patent/CN112015595B/en
Publication of CN112015595A publication Critical patent/CN112015595A/en
Application granted granted Critical
Publication of CN112015595B publication Critical patent/CN112015595B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1461Backup scheduling policy
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Abstract

The invention discloses a method for switching a master database and a slave database, a computing device and a storage medium, wherein the method comprises the following steps: monitoring whether a current first main database is down; when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database; synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing a master-slave synchronization function; selecting a new third main database; reading data to be synchronized of the first master database by using a plug-in the first master database, and writing the data to be synchronized of the first master database into the third master database; and updating the configuration information of the master database and the slave database after switching. By the scheme of the invention, when the current main database is down, the slave database can be switched into the main data in time, and the data can be ensured not to be lost.

Description

Master-slave database switching method, computing device and storage medium
Technical Field
The invention relates to the technical field of databases, in particular to a master-slave database switching method, computing equipment and a storage medium.
Background
The master-slave database is generally composed of a master database and a plurality of slave databases, wherein the master database has data reading and writing functions, and the slave databases can independently provide data reading functions to business parties by keeping synchronization with data in the master database, thus dispersing the access pressure of the master database and solving the problem of slow data reading from the master database only. Meanwhile, the availability of the master database is a precondition for realizing the reading and writing and the voltage division of the master database, namely, master data which normally provides a data reading and writing function is required to be always kept.
In the prior art, the authority of a master database and each slave database is generally obtained, when the current database is down, the authority of the master database is utilized to fetch data from the master database, then the authority of a slave database suitable for being used as a new master database is utilized to go to the slave database, the data is sent to the slave database, and then the slave database is lifted to be a new master database.
However, the inventor finds that the prior art at least has the following technical problems in the process of implementing the embodiment of the invention: in the prior art, the authority of each database must be possessed, and the authority is used for taking data from the master database and sending the taken data to the new master database, so that the efficiency of database switching is greatly reduced, the service cannot be used for a long time, and the fault perception of a user is enhanced.
Disclosure of Invention
In view of the above problems, embodiments of the present invention are proposed to provide a switching method of a master-slave database, a computing device and a storage medium that overcome or at least partially solve the above problems.
According to an aspect of the embodiments of the present invention, a method for switching a master database and a slave database is provided, including:
monitoring whether a current first main database is down;
when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database;
synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing a master-slave synchronization function;
selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases;
querying data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result;
and updating the configuration information of the master database and the slave database after switching.
According to yet another aspect of the present invention, there is provided a computing device comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the switching method of the master database and the slave database.
According to another aspect of the embodiments of the present invention, a computer storage medium is provided, where at least one executable instruction is stored in the storage medium, and the executable instruction causes a processor to execute an operation corresponding to a method for switching between a master database and a slave database.
According to the switching method of the master database and the slave database, the computing equipment and the storage medium, after the current first master database is monitored to be down, the temporary second master database is selected according to the data synchronization position information of each slave database, and the data in other slave databases are synchronized to be consistent with the data in the temporary second master database by utilizing the master-slave synchronization function, so that the data volume for completing by utilizing plug-ins subsequently is reduced; then, after the data synchronization is completed, selecting a new third main database based on the role weight configuration information, and supplementing the data to be synchronized of the first database into the third main database by using the plug-in the first main database, so that the data in the third main database is completely consistent with the data in the first database before the downtime, and the data loss of the third main database is avoided, so that the third main database can provide the same service as the first main database; and finally, modifying the configuration information of the master database and the slave database so as to facilitate the service party to read and request the service. Therefore, according to the scheme of the invention, the data of the new third main database is completely consistent with the data in the down first main database through the master-slave synchronization function and the plug-in completion mode, and compared with the mode that the data is fetched from the old main database and sent into the new main database through the database authority obtaining in the prior art, the overall switching efficiency can be improved.
The foregoing description is only an overview of the technical solutions of the embodiments of the present invention, and the embodiments of the present invention can be implemented according to the content of the description in order to make the technical means of the embodiments of the present invention more clearly understood, and the detailed description of the embodiments of the present invention is provided below in order to make the foregoing and other objects, features, and advantages of the embodiments of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the embodiments of the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 shows a flowchart of a method for switching a master database and a slave database according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for switching between master and slave databases according to another embodiment of the present invention;
FIG. 3 shows a schematic diagram of a master-slave database structure in one specific example;
FIG. 4 is a schematic diagram illustrating a data completion process for the master-slave database of FIG. 3;
fig. 5 is a schematic structural diagram of a computing device provided by an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Fig. 1 shows a flowchart of a method for switching a master database and a slave database according to an embodiment of the present invention. The method is used for switching one slave database in the master database and the slave database into a new master database when the current master database is down. The method can be performed by any computing device with data processing capabilities, preferably having a switching system dedicated to master-slave database switching. As shown in fig. 1, the method comprises the steps of:
step S110: and monitoring whether the current first main database is down.
The first master database is the master database which provides the read-write function at present.
Specifically, whether the first main database is down is monitored continuously in real time, and once the first main database is monitored to be down, the step S120 and the subsequent steps are executed to realize the timely switching of the main databases and avoid influencing the service.
Step S120: when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database; and synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing the master-slave synchronization function.
In practice, there are differences in the transmission rate of the master database for data synchronization to each slave database, resulting in incomplete consistency of the synchronized data in each slave database. The data synchronization position information of any slave database refers to existing synchronization data in the slave database, and the data synchronization position information can reflect the synchronization progress in the data position in the first master database. For example, if the data synchronization location information of the slave database 1 is 9, it indicates that the synchronization data in the slave database 1 is synchronized to the 9 th data in the first master database.
Specifically, the data synchronization position information of each slave database may reflect respective synchronization progress, where the faster the synchronization progress, the more existing synchronization data is represented, and the less data to be synchronized is represented, and accordingly, the less workload for subsequent synchronization is required, and based on this, a temporary second master database is selected from the multiple slave databases to be used for synchronizing data with other slave databases, so as to reduce the workload for subsequent synchronization. It should be noted that, the present invention is not limited to a specific selection manner, for example, the slave database with the fastest synchronization progress displayed by the data synchronization position information may be selected as the temporary second slave database to reduce the data amount synchronized by the subsequent plug-in to the maximum extent, or the slave database with the optimal network configuration may be selected as the temporary second slave database from the slave databases with the synchronization progress displayed by the data synchronization position information ranked in the previous preset rank, so that when the data amount synchronized by the subsequent plug-in is reduced, the data synchronization in the plurality of slave databases is further ensured to be realized in the shortest possible time by using the good network configuration.
And after the second master database is selected, synchronizing the data to be synchronized of the second master database to other slave databases by using a master-slave synchronization function of the master-slave database, wherein the master-slave synchronization function is an internal mechanism of the master-slave database, and compared with other auxiliary data synchronization implementation modes (including an authority acquisition synchronization mode in the prior art and a plug-in synchronization mode in the following text), the efficiency of synchronizing the data is the highest, and a plurality of slave databases can be efficiently synchronized to a consistent position. And each other slave database has the data to be synchronized of the corresponding second master database, and if the data synchronization position information of the other slave databases is different, the data to be synchronized of the second master databases of the other slave databases is different.
For example, if the data synchronization position information of the second master database is 10, and the data synchronization position information of the other slave databases 1 and 2 is 9 and 8, respectively, the data to be synchronized of the second master database is the latest data (10-9 is equal to 1) with respect to the slave database 1, and the data to be synchronized of the second master database is the latest data (10-8 is equal to 2) with respect to the slave database 2, the data to be synchronized is synchronized to the slave database 1 and the slave database 2 by using the master-slave synchronization function, and after the synchronization is completed, the synchronization data of the second master database, the slave database 1 and the slave database 2 are 10, and the synchronization is maintained to be consistent.
Step S130: selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases; and querying the data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result.
Wherein the role weight configuration information is an index suitable as a new third master database, which reflects the priority of the temporary second master database and other slave databases selected as the new third master database.
And a data completion plug-in (referred to as plug-in for short herein) is deployed in the first main database, and is used for performing completion processing on the synchronous data in the third main database by using the plug-in when the first main database is down. Because the first main database is down, data completion can be performed only in an auxiliary manner (in this embodiment, in a plug-in manner), and missing data in the new third main database is avoided.
Specifically, according to the priority ranking reflected by the role weight configuration information of the temporary second master database and other slave databases, new third master data is selected to replace the first master database. After a new third main database is selected, the plug-in the first main database is used for inquiring the data to be synchronized in the first main database, and the inquired data to be synchronized is complemented into the third main database, so that the third main database has data consistent with the first main database before downtime, wherein the data to be synchronized in the first main database refers to data existing in the first main database and data not existing in the third main database. In this embodiment, the temporary second master database is selected first and synchronized by the master-slave synchronization function, so that the amount of data to be complemented by the plug-in subsequently can be reduced, and then the plug-in is used for complementing, so that the efficiency of the whole process of synchronizing the data in the first master database to the third master database can be improved while the consistency of the data in the master databases before and after switching is ensured.
Step S140: and updating the configuration information of the master database and the slave database after switching.
After completing the completion of the data in the first master database into the third master database, the configuration information of the master-slave database is modified, so that the business side can continue to obtain services from the master-slave database by reading the updated configuration.
According to the switching method of the master database and the slave database provided by the embodiment, after the current first master database is monitored to be down, the temporary second master database is selected according to the data synchronization position information of each slave database, and the data in other slave databases are synchronized to be consistent with the data in the temporary second master database by using the master-slave synchronization function, so that the data volume complemented by a plug-in is reduced; then, after the data synchronization is completed, selecting a new third main database based on the role weight configuration information, and supplementing the data to be synchronized of the first database into the third main database by using the plug-in the first main database, so that the data in the third main database is completely consistent with the data in the first database before the downtime, and the data loss of the third main database is avoided, so that the third main database can provide the same service as the first main database; and finally, modifying the configuration information of the master database and the slave database so as to facilitate the service party to read and request the service. Therefore, according to the scheme of the embodiment, the data of the new third main database is completely consistent with the data in the down first main database through the master-slave synchronization function and the plug-in completion mode, and compared with the mode that the data is fetched from the old main database and sent into the new main database through the database permission obtaining in the prior art, the overall switching efficiency can be improved.
Fig. 2 is a flowchart illustrating a method for switching between a master database and a slave database according to another embodiment of the present invention. The master-slave database may be any type of database known to those skilled in the art, such as a mysql database, which is not listed here. As shown in fig. 2, the method comprises the steps of:
step S210: and monitoring whether the current first main database is down.
In the invention, the specific mode of monitoring whether the first main database is down is not limited, and in actual implementation, a person skilled in the art can flexibly select the first main database according to the actual situation. Typically, a connection is made to a master database and the master database's heartbeat is monitored to determine if the master database is down.
In some alternative embodiments, the monitoring may be performed by establishing connections with the first master database and the plurality of slave databases, that is, establishing connections between the computing device executing the embodiment of the present invention or a switching system in the computing device and each of the master databases and the slave databases, and then performing the monitoring in the following manner; monitoring whether communication with the first master database is available, and if not, inquiring whether the plurality of slave databases are connected with the first master database; and judging whether the first main database is down or not according to the query results returned by the plurality of slave databases. In these alternative embodiments, the two-layer monitoring is performed to finally determine whether the downtime occurs by utilizing the communication between the computing device (or the switching system) and the first master database and the connection status of each slave database with the first master database, so as to improve the accuracy of the downtime monitoring. Further, in a case where the computing device (or the switching system) is not communicable with the first master database, whether the first master database is down may be determined according to the number of the slave databases returning the query results that are not connected with the first master database, for example, if the number of the slave databases exceeding a preset number returns the query results that are not connected with the first master database, the first master database is determined to be down; preferably, if all the slave databases return the query result which is not connected with the first master database, it is determined that the first master database is down.
In addition, in the embodiment of the present invention, it is also necessary to detect whether the master database and/or the slave database of the master-slave database is updated; if so, establishing connection with the newly added main database and/or the slave database, or disconnecting the connection with the deleted main database and/or the slave database, so as to ensure that the downtime monitoring can be accurately carried out on the first main database,
step S220: determining a target slave database with the fastest synchronization progress according to the data synchronization position information of each slave database; selecting the target from the database as a temporary second master database; and synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing the master-slave synchronization function.
In the embodiment of the invention, the temporary second master database is selected according to the amount of the synchronous data.
Specifically, the data synchronization position information of the plurality of slave databases is compared, the target slave database with the fastest synchronization progress is determined, the target slave database is selected as a temporary second master database, and then data synchronization is performed between the second master database and the rest slave databases by using a master-slave synchronization function, so that the synchronization data in the other slave databases can be synchronized to be consistent with the data in the second master database, and the maximum synchronization data is achieved.
Fig. 3 shows a schematic diagram of a master-slave database structure in one specific example. As shown in fig. 3, the databases with IP of 1.1.1.1 are the first master database, and the databases with IP of 2.2.2.2, 3.3.3.3 and 4.4.4.4 are the slave database 1, the slave database 2 and the slave database 3, respectively, where the data points are data synchronization location information, the data points of the slave database represent the locations of the synchronization data copied from the first master database to each slave database, for example, the data point of the slave database 1 is 9, which represents synchronization to the 9 th data, when the first master database is down, the data cannot be normally copied to each slave database, and when the size of the data point is compared to determine that the synchronization progress of the slave database 2 is fastest, the slave database 2 is selected as the temporary second master database. Then, the data in the slave database 1 and the slave database 3 are synchronized to be consistent with the data in the slave data 2 by using the master-slave synchronization function, and 10 pieces of data are obtained.
Step S230: and selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases.
Specifically, after the master-slave synchronization is completed, role weight configuration information is set for the slave databases according to the machine configurations of the slave databases so that the role weights of the slave databases are adapted to the machine configurations thereof, and normally, the role weight configuration information of the reflected role weights from high to low is set for the slave databases according to the machine configurations from high to low. The slave database which is only used for backup is usually low in hardware configuration and is not enough to be used as a master database to provide a data reading and writing function, and correspondingly, the role weight of the slave database which is only used for backup is set to be the lowest, for example, 0, so that the slave database is prevented from being selected as a new master database. And then, selecting a second master database or other slave databases with the highest role weight as a new third master database according to the role weight configuration information, in other words, selecting a slave database with the optimal machine configuration as a new third master database so as to ensure the read-write performance of the master-slave data after the master databases are switched.
Still taking fig. 3 as an example, the role of each slave database in fig. 3 is role weight configuration information, and the role weight configuration information of the slave database 1, the slave database 2, and the slave database 3 are a candidate master library, a backup slave library, and an optional master library, respectively, where the candidate master library reflects the highest role weight, the optional master library is the second, and the backup slave library is the lowest, which cannot be used as a new master library. Corresponding to fig. 3, after synchronizing the data of the slave database 1 and the slave database 3 to be consistent with the data in the temporary third master database (i.e., the slave database 2), the slave database 1 is selected as a new third master database.
In some optional embodiments of the present invention, after selecting a new third master database, a confirmation notification of master-slave database switching is sent to the user for the user to confirm the switching, for example, by sending an email for the user to confirm; and responding to the confirmation operation of the user, and executing subsequent data completion and configuration updating operation. In these optional embodiments, the subsequent switching operation is continued after the user confirms, and when the network is jittered, subsequent data completion and configuration update may not be performed because the user does not perform the confirmation operation, so as to prevent the switching from being down again after the switching is performed due to the network jitter, taking fig. 3 as an example, the switching is down after the switching is performed to the slave database 1, and then the switching is down again after the switching is performed to the slave database 3.
Step S240: and querying the data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result.
In practice, plug-ins may be deployed in each database, so that after any database is taken as a main database and crashed, the plug-ins in the database may be used to complete the data in the new main database.
Specifically, a data query request is sent to a plug-in of the first master database, and the plug-in queries data to be synchronized of the first master database according to the data query request, wherein data synchronization position information of the third master database after the master-slave synchronization, for example, a data point 10, may be carried in the data query request, so that the plug-in queries whether data to be synchronized of the first master database exists, where the data to be synchronized of the first master database is that the data to be synchronized of the first master database does not exist in the third master database after the master-slave synchronization, but exists in the first master database; then, after the data to be synchronized of the first main data is inquired, writing the data to be synchronized of the first main database into the third main database; if the data to be synchronized of the first main database does not exist, the process of data completion processing can be omitted, and the subsequent step of updating the configuration information is executed. By the method, the temporary second main database can not be synchronized to the data in the third main database, and the plug-in is used for completing, so that data omission is avoided.
Fig. 4 is a schematic diagram illustrating a data completion process for the master-slave database of fig. 3. As shown in fig. 4, after the slave database 1 is selected as a new third master database, the topology structure of the master-slave database becomes 1 master (third master database) 2 slave (slave database 2 and slave database 3), and after master-slave synchronization, the data in the 1 master 2 is synchronized to 10, and the data completion process is as follows: 1: the switching system sends a query request for querying whether data larger than 10 exists to the plug-in of the first main database; 2: since the data in the first master database is 12, i.e. has data 11 and 12 to be synchronized, the plug-in returns data 11 and 12 to the switching system; 3: the switching system writes the data 11 and 12 into the third master database; 4: after the write is successful, the configuration update is performed on the master-slave database (the content of step S250 described below).
In the above steps S220 to S240, a temporary second master database with the fastest synchronization progress is selected first, and then a third master database with the highest role weight is selected, so that complete data synchronization is achieved by sequentially using the master-slave synchronization function and the plug-in. In other embodiments of the present invention, it may be determined whether the slave database with the highest synchronization progress is the slave database with the highest role weight, if so, the slave database with the highest synchronization progress is directly determined as the third master database, and the plug-in is used to implement complete data synchronization at one time, so that the process of master-slave synchronization may be omitted, and the switching efficiency for the special situation may be further improved.
Step S250: and updating the configuration information of the master database and the slave database after switching.
Specifically, the master database in the configuration information is updated from the first master database to the third master database, and the information of the first master database is deleted.
According to the switching method of the master-slave databases provided by the embodiment, after the current first master database is monitored to be down, the target slave database with the fastest synchronization progress is selected from the multiple slave databases to serve as the temporary second master database, and the data to be synchronized of the temporary second master database is quickly synchronized to other slave databases by using the master-slave synchronization function, so that the data in other slave databases are synchronized to the latest data in all the slave databases, the data volume complemented by subsequent plug-ins is reduced as much as possible, and the switching efficiency is improved; after synchronization is completed, selecting a slave database with the highest role weight as a new third master database according to role weight configuration information, wherein the role weight configuration information is set according to machine configuration, so that the slave database with the highest current machine configuration can be selected as the new third master database each time, and the performance of the master database is guaranteed; secondly, on the basis of completing data synchronization by using master-slave synchronization, completing the data in the third master database by using a plug-in to ensure that the data in the new third master database is consistent with the data in the first master database and avoid data omission; and finally, updating the configuration of the master database and the slave database so that the service party can obtain service according to the configuration.
The embodiment of the invention provides a nonvolatile computer storage medium, wherein at least one executable instruction is stored in the computer storage medium, and the computer executable instruction can execute the switching method of the master database and the slave database in any method embodiment.
The executable instructions may be specifically configured to cause the processor to:
monitoring whether a current first main database is down;
when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database;
synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing a master-slave synchronization function;
selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases;
querying data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result;
and updating the configuration information of the master database and the slave database after switching.
In an alternative, the executable instructions further cause the processor to:
establishing a connection with the first master database and a plurality of slave databases;
monitoring whether communication with the first master database is available, and if not, inquiring whether the plurality of slave databases are connected with the first master database;
and judging whether the first main database is down or not according to the inquiry results returned by the plurality of slave databases.
In an alternative, the executable instructions further cause the processor to:
and if all the slave databases return inquiry results which are not connected with the first master database, judging that the first master database is down.
In an alternative, the executable instructions further cause the processor to:
determining a target slave database with the fastest synchronization progress according to the data synchronization position information of each slave database; and selecting the target from the database as a temporary second master database.
In an alternative, the executable instructions further cause the processor to:
and selecting the second master database with the highest role weight or other slave databases as a new third master database according to the role weight configuration information.
In an alternative, the executable instructions further cause the processor to:
setting role weight configuration information for the plurality of slave databases according to the machine configuration of the plurality of slave databases.
In an alternative, the executable instructions further cause the processor to:
sending a data query request to a plug-in of the first master database, and querying data to be synchronized of the first master database by the plug-in according to the data query request;
and after the data to be synchronized of the first master database is inquired, writing the data to be synchronized of the first master database into the third master database.
In an alternative, the executable instructions further cause the processor to:
sending a confirmation notice of master-slave database switching to a user for the user to confirm the switching;
and responding to the confirmation operation of the user, inquiring the data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to the inquiry result.
In an alternative, the executable instructions further cause the processor to:
and updating the master database in the configuration information from the first master database to a third master database.
In an alternative, the executable instructions further cause the processor to:
detecting whether a master database and/or a slave database of the master-slave database are updated or not;
if yes, connection with the newly added master database and/or the slave database is established, and/or connection with the deleted master database and/or the slave database is disconnected.
In an alternative approach, the master-slave database is a mysql database.
Fig. 5 is a schematic structural diagram of a computing device according to an embodiment of the present invention, and the specific embodiment of the present invention does not limit the specific implementation of the computing device.
As shown in fig. 5, the computing device may include: a processor (processor)502, a Communications Interface 504, a memory 506, and a communication bus 508.
Wherein: the processor 502, communication interface 504, and memory 506 communicate with one another via a communication bus 508. A communication interface 504 for communicating with network elements of other devices, such as clients or other servers. The processor 502 is configured to execute the program 510, and may specifically perform relevant steps in the foregoing method for switching between the master database and the slave database of the computing device.
In particular, program 510 may include program code that includes computer operating instructions.
The processor 502 may be a central processing unit CPU, or an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits configured to implement an embodiment of the present invention. The computing device includes one or more processors, which may be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 506 for storing a program 510. The memory 506 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 510 may specifically be used to cause the processor 502 to perform the following operations:
monitoring whether a current first main database is down;
when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database;
synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing a master-slave synchronization function;
selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases;
querying data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result;
and updating the configuration information of the master database and the slave database after switching.
In an alternative, the program 510 further causes the processor 502 to:
establishing a connection with the first master database and a plurality of slave databases;
monitoring whether communication with the first master database is available, and if not, inquiring whether the plurality of slave databases are connected with the first master database;
and judging whether the first main database is down or not according to the inquiry results returned by the plurality of slave databases.
In an alternative, the program 510 further causes the processor 502 to:
and if all the slave databases return inquiry results which are not connected with the first master database, judging that the first master database is down.
In an alternative, the program 510 further causes the processor 502 to:
determining a target slave database with the fastest synchronization progress according to the data synchronization position information of each slave database; and selecting the target from the database as a temporary second master database.
In an alternative, the program 510 further causes the processor 502 to:
and selecting the second master database with the highest role weight or other slave databases as a new third master database according to the role weight configuration information.
In an alternative, the program 510 further causes the processor 502 to:
setting role weight configuration information for the plurality of slave databases according to the machine configuration of the plurality of slave databases.
In an alternative, the program 510 further causes the processor 502 to:
sending a data query request to a plug-in of the first master database, and querying data to be synchronized of the first master database by the plug-in according to the data query request;
and after the data to be synchronized of the first master database is inquired, writing the data to be synchronized of the first master database into the third master database.
In an alternative, the program 510 further causes the processor 502 to:
sending a confirmation notice of master-slave database switching to a user for the user to confirm the switching;
and responding to the confirmation operation of the user, inquiring the data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to the inquiry result.
In an alternative, the program 510 further causes the processor 502 to:
and updating the master database in the configuration information from the first master database to a third master database.
In an alternative, the program 510 further causes the processor 502 to:
detecting whether a master database and/or a slave database of the master-slave database are updated or not;
if yes, connection with the newly added master database and/or the slave database is established, and/or connection with the deleted master database and/or the slave database is disconnected.
In an alternative approach, the master-slave database is a mysql database.
The algorithms or displays presented herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. In addition, embodiments of the present invention are not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of embodiments of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best modes of embodiments of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the embodiments of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that is, the claimed embodiments of the invention require more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components according to embodiments of the present invention. Embodiments of the invention may also be implemented as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing embodiments of the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. Embodiments of the invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names. The steps in the above embodiments should not be construed as limiting the order of execution unless specified otherwise.

Claims (12)

1. A method for switching master and slave databases comprises the following steps:
monitoring whether a current first main database is down;
when the current first main database is monitored to be down, selecting a temporary second main database from the plurality of slave databases according to the data synchronization position information of each slave database; selecting a slave database with the highest synchronous progress displayed by the data synchronous position information as a temporary second master database, or selecting a slave database with the optimal network configuration as a temporary second master database from slave databases with the synchronous progress displayed by the data synchronous position information arranged in the past by preset names;
synchronizing the data to be synchronized of the temporary second master database to other slave databases by utilizing a master-slave synchronization function, so that the data in the other slave databases are synchronized to be consistent with the data in the second master database;
selecting a new third master database according to the role weight configuration information of the temporary second master database and the other slave databases;
querying data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to a query result;
and updating the configuration information of the master database and the slave database after switching.
2. The method of claim 1, wherein the method further comprises: establishing a connection with the first master database and a plurality of slave databases;
the monitoring whether the current first main database is down further comprises:
monitoring whether communication with the first master database is available, and if not, inquiring whether the plurality of slave databases are connected with the first master database;
and judging whether the first main database is down or not according to the inquiry results returned by the plurality of slave databases.
3. The method of claim 2, wherein said determining whether said first master database is down according to said plurality of query results returned from said database further comprises:
and if all the slave databases return inquiry results which are not connected with the first master database, judging that the first master database is down.
4. The method of claim 1, wherein said selecting a new third master database based on role weight configuration information of the temporary second master database and the other slave databases further comprises:
and selecting the second master database with the highest role weight or other slave databases as a new third master database according to the role weight configuration information.
5. The method of claim 1, wherein the method further comprises:
setting role weight configuration information for the plurality of slave databases according to the machine configuration of the plurality of slave databases.
6. The method according to any one of claims 1-5, wherein the querying the data to be synchronized of the first master database by using the plug-in the first master database, and performing the data completion process on the third master database according to the query result further comprises:
sending a data query request to a plug-in of the first master database, and querying data to be synchronized of the first master database by the plug-in according to the data query request;
and after the data to be synchronized of the first master database is inquired, writing the data to be synchronized of the first master database into the third master database.
7. The method according to any of claims 1-5, wherein after said selecting a new third master database, the method further comprises:
sending a confirmation notice of master-slave database switching to a user for the user to confirm the switching;
the querying, by using the plug-in the first master database, the data to be synchronized in the first master database, and performing data completion processing on the third master database according to the query result specifically include:
and responding to the confirmation operation of the user, inquiring the data to be synchronized of the first master database by using the plug-in the first master database, and performing data completion processing on the third master database according to the inquiry result.
8. The method according to any one of claims 1-5, wherein the updating the configuration information of the switched master-slave database further comprises:
and updating the master database in the configuration information from the first master database to a third master database.
9. The method of any of claims 1-5, wherein the method further comprises:
detecting whether a master database and/or a slave database of the master-slave database are updated or not;
if yes, connection with the newly added master database and/or the slave database is established, and/or connection with the deleted master database and/or the slave database is disconnected.
10. The method of any of claims 1-5, wherein the master-slave database is a mysql database.
11. A computing device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the switching method of the master-slave database as claimed in any one of claims 1-10.
12. A computer storage medium having stored therein at least one executable instruction for causing a processor to perform operations corresponding to the method for switching between master and slave databases as claimed in any one of claims 1 to 10.
CN202010887335.5A 2020-08-28 2020-08-28 Master-slave database switching method, computing device and storage medium Active CN112015595B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010887335.5A CN112015595B (en) 2020-08-28 2020-08-28 Master-slave database switching method, computing device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010887335.5A CN112015595B (en) 2020-08-28 2020-08-28 Master-slave database switching method, computing device and storage medium

Publications (2)

Publication Number Publication Date
CN112015595A CN112015595A (en) 2020-12-01
CN112015595B true CN112015595B (en) 2021-03-02

Family

ID=73502355

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010887335.5A Active CN112015595B (en) 2020-08-28 2020-08-28 Master-slave database switching method, computing device and storage medium

Country Status (1)

Country Link
CN (1) CN112015595B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112749045B (en) * 2021-01-11 2023-05-26 深圳市伊欧乐科技有限公司 Database cluster switching method, device, storage medium and apparatus
CN115934428B (en) * 2023-01-10 2023-05-23 湖南三湘银行股份有限公司 Main disaster recovery and backup switching method and device of MYSQL database and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104036043A (en) * 2014-07-01 2014-09-10 浪潮(北京)电子信息产业有限公司 High availability method of MYSQL and managing node
CN108984569A (en) * 2017-06-05 2018-12-11 中兴通讯股份有限公司 Database switching method, system and computer readable storage medium
CN110413692A (en) * 2019-07-30 2019-11-05 中国工商银行股份有限公司 Data processing method and server for data-base cluster
CN111200532A (en) * 2020-01-02 2020-05-26 广州虎牙科技有限公司 Method, device, equipment and medium for master-slave switching of database cluster node

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10089307B2 (en) * 2014-12-31 2018-10-02 International Business Machines Corporation Scalable distributed data store
CN104765889A (en) * 2015-04-30 2015-07-08 北京奇虎科技有限公司 Switching method and device of high-availability frame based on database
CN104866556B (en) * 2015-05-15 2019-07-23 北京奇虎科技有限公司 Fault handling method, device and the Database Systems of database
CN108038157A (en) * 2017-12-05 2018-05-15 北京星河星云信息技术有限公司 Master-slave database reading/writing method, system, storage device and server
CN111078463B (en) * 2018-10-19 2023-05-02 阿里云计算有限公司 Data backup method, device and system
CN110413685B (en) * 2019-04-12 2024-03-12 财付通支付科技有限公司 Database service switching method, device, readable storage medium and computer equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104036043A (en) * 2014-07-01 2014-09-10 浪潮(北京)电子信息产业有限公司 High availability method of MYSQL and managing node
CN108984569A (en) * 2017-06-05 2018-12-11 中兴通讯股份有限公司 Database switching method, system and computer readable storage medium
CN110413692A (en) * 2019-07-30 2019-11-05 中国工商银行股份有限公司 Data processing method and server for data-base cluster
CN111200532A (en) * 2020-01-02 2020-05-26 广州虎牙科技有限公司 Method, device, equipment and medium for master-slave switching of database cluster node

Also Published As

Publication number Publication date
CN112015595A (en) 2020-12-01

Similar Documents

Publication Publication Date Title
CN109308227B (en) Fault detection control method and related equipment
CN107919977B (en) Online capacity expansion and online capacity reduction method and device based on Paxos protocol
CN108123851B (en) Survival detection method and device for master-slave node synchronous link in distributed system
CN108762668B (en) Method and device for processing write conflict
US20160350350A1 (en) Ensuring the same completion status for transactions after recovery in a synchronous replication environment
CN112015595B (en) Master-slave database switching method, computing device and storage medium
CN110673941A (en) Migration method of micro-services in multiple computer rooms, electronic equipment and storage medium
CN113094430B (en) Data processing method, device, equipment and storage medium
CN112052230B (en) Multi-machine room data synchronization method, computing device and storage medium
CN108228812B (en) Self-adaptive main node switching method and device
CN108205588B (en) Data synchronization method and device based on master-slave structure
CN113468143A (en) Data migration method, system, computing device and storage medium
WO2021082925A1 (en) Transaction processing method and apparatus
CN114625566A (en) Data disaster tolerance method and device, electronic equipment and storage medium
CN113055203B (en) Method and device for recovering exception of SDN control plane
CN107547605B (en) message reading and writing method based on node queue and node equipment
EP3811227B1 (en) Methods, devices and systems for non-disruptive upgrades to a distributed coordination engine in a distributed computing environment
CN112000850A (en) Method, device, system and equipment for data processing
WO2024036829A1 (en) Data fusion method and apparatus, and device and storage medium
CN107943615B (en) Data processing method and system based on distributed cluster
US10341434B2 (en) Method and system for high availability topology for master-slave data systems with low write traffic
CN112711466B (en) Hanging affair inspection method and device, electronic equipment and storage medium
CN110502460B (en) Data processing method and node
CN109901933B (en) Operation method and device of business system, storage medium and electronic device
CN112068972A (en) Message queue consumption method based on multi-computer room realization and electronic equipment

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
GR01 Patent grant
GR01 Patent grant