A master-slave switching method, device, equipment and medium for database
By receiving and generating end logs in the consistency component of the database, the log reception completion problem is solved when the master database fails, and the timely role switching of the slave database is realized, and the efficiency of master-slave switching is improved.
Patent Information
- Application Number
- CN202010844971.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-20
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2040-08-20
AI Technical Summary
In the event of a master database failure, it is impossible to determine whether its complete log is received, resulting in untimely switching between master and slaves, affecting strong data consistency between database instances.
By receiving master-slave switching data and target logs in the consistent component of the target slave database, an end log is generated and sent to the target slave database, switching it to the new master database based on the end log and target log.
The master database log reception is completed before the slave database is determined before the switch is switched, avoiding the problem of untimely switching between master and slave roles and improving the efficiency of master and slave switching in the database instance.
Smart Images

Figure CN114077520B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of databases, and in particular to a master-slave switching method, device, equipment and medium for a database. Background Art
[0002] In order to prevent data loss in the database, multiple databases with a master-slave architecture can be used to synchronize data. If the master database fails, a new master database needs to be determined among multiple slave databases. The above process is called master-slave switching.
[0003] Before switching from a slave database to a new master database, it is necessary to ensure that the complete log sent by the previous master database is received. However, because the previous master database has failed, the new master database cannot be sure whether it has received its complete log and cannot implement master-slave switching in time. Summary of the invention
[0004] In order to solve the above technical problem or at least partially solve the above technical problem, the present disclosure provides a master-slave switching method, device, equipment and medium of a database.
[0005] The present disclosure provides a master-slave switching method for a database, the method being applied to a consistency component corresponding to a target slave database, and comprising:
[0006] Receiving master-slave switching data and a target log, wherein the target log is a log of a target master database;
[0007] Generate an end log based on the master-slave switching data;
[0008] The end log and the target log are sent to the target slave database, so that the target slave database is switched to a new master database based on the end log and the target log.
[0009] The embodiment of the present disclosure further provides a master-slave switching device for a database, wherein the device is configured in a consistency component in a target slave database, and comprises:
[0010] A data receiving module, used to receive master-slave switching data and a target log, wherein the target log is a log of a target master database;
[0011] An end log module, used for generating an end log based on the master-slave switching data;
[0012] The master-slave switching module is used to send the end log and the target log to the target slave database, so that the target slave database is switched to a new master database based on the end log and the target log.
[0013] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the master-slave switching method of the database provided in the embodiment of the present disclosure.
[0014] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the master-slave switching method of the database provided by the embodiment of the present disclosure.
[0015] The technical solution provided by the embodiment of the present disclosure has the following advantages over the prior art: the master-slave switching solution for the database provided by the embodiment of the present disclosure, the consistency component corresponding to the target slave database can receive the master-slave switching data and the target log, wherein the target log is the log of the target master database; an end log is generated based on the master-slave switching data; the end log and the target log are sent to the target slave database, so that the target slave database is switched to the new master database based on the end log and the target log. With the above technical solution, before the master-slave switching is performed, the slave database can receive the end log generated by its corresponding consistency component, and determine the completion of the log reception of the previous master database based on the end log, thereby realizing the master-slave role switching of the slave database and switching to the new master database, thus avoiding the problem of untimely master-slave role switching due to the uncertainty of whether the log reception is complete in the prior art, and improving the efficiency of master-slave switching of database instances. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1 A schematic diagram of a process flow of a master-slave switching method of a database provided in an embodiment of the present disclosure;
[0019] Figure 2 A flowchart of another master-slave switching method of a database provided by an embodiment of the present disclosure;
[0020] Figure 3 A log transmission schematic diagram of a database provided in an embodiment of the present disclosure;
[0021] Figure 4A schematic diagram of master-slave switching of a database provided in an embodiment of the present disclosure;
[0022] Figure 5 A schematic diagram of the structure of a master-slave switching device for a database provided in an embodiment of the present disclosure;
[0023] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0025] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0026] In order to prevent data loss in the database, multiple databases with a master-slave architecture can be used to synchronize data. The master database can be responsible for providing normal database access functions so that users can operate data. The master database can also copy data to the slave database through the data replication protocol. The data on the slave database is sent by the master database, so the data in the slave database is consistent with the data in the master database. If the master database cannot be used normally due to a failure, a new master database can be elected from multiple slave databases. The above process is the master-slave switch.
[0027] Before switching from a database to a new master database, it is necessary to ensure that the complete log sent by the previous master database is received. However, because the previous master database has failed, the new master database cannot be sure whether it has received its complete log, and cannot implement master-slave switching in time. In the prior art, the data replication module does not have the above-mentioned problem when it is an internal function of the database, but this method is not conducive to the strong consistency of data between database instances. In the disclosed embodiment, the data replication module can be run as an independent plug-in with storage function. The data replication module and the general consistency component can cooperate to realize the log transmission between the master database and the slave database, thereby realizing the strong consistency of data. In order to effectively realize the strong consistency of data between databases and realize the master-slave switching in time when the master database fails, the disclosed embodiment provides a master-slave switching method for a database.
[0028] Figure 1The present invention provides a flowchart of a master-slave switching method for a database, which can be performed by a master-slave switching device for a database, wherein the device can be implemented by software and / or hardware, and can generally be integrated in an electronic device. Figure 1 As shown, the method is applied to the consistency component corresponding to the target slave database, including:
[0029] Step 101: Receive master-slave switching data and a target log, wherein the target log is a log of a target master database.
[0030] In the disclosed embodiment, the target slave database is a historical slave database that is about to be switched to a new master database, and the target master database is a historical master database to be switched to a new slave database, that is, the target master database may be a historical master database that has failed. The consistency component is a general component used to achieve strong consistency of data between databases, and both the master database and the slave database are configured with corresponding consistency components.
[0031] A database instance is a memory structure used to manage database files. In simple terms, it is a series of system processes (or threads) and memory blocks allocated to these processes (or threads). A database instance is an independent logical concept that users can access, and users can access data through database instances. The disclosed embodiment is described with each database corresponding to a database instance, which may specifically include a master database instance and at least one slave database instance. The master database can be accessed through the master database instance. A data replication module is configured in each database instance. The master database instance and the slave database instance can realize data replication of the master database and the slave database through the data replication module to ensure strong consistency of the data. Among them, the data replication module is implemented based on the consistency protocol (Raft protocol), and the data replication module can be configured in each database instance in the form of an independent plug-in to support storage logs.
[0032] The master-slave switching data is data used to record changes in the master-slave attributes of the database. Specifically, it can store the database identifier of the slave database switching to the master database and the database identifier of the master database switching to the slave database, that is, the database identifier of the above-mentioned target slave database and the database identifier of the above-mentioned target master database. After the database replication module determines the new master database through the election algorithm, that is, after determining the target slave database, the master-slave switching data can store relevant data. And the master-slave switching data is located at the end of the target log. The target log is the database log that needs to be synchronized to the target slave database.
[0033] In the disclosed embodiment, receiving the master-slave switching data and the target log includes: receiving the master-slave switching data and the target log sent after the target master database fails. After the target master database fails, its data replication module can elect a new master database, i.e., the target slave database, from multiple historical slave databases based on an election algorithm, and send the local database log and the master-slave switching data to the data replication module corresponding to the target slave database. After receiving the target log and the master-slave switching data, the data replication module corresponding to the target slave database sends them to the consistency component, and the consistency component can receive the above-mentioned target log and the master-slave switching data.
[0034] Step 102: Generate an end log based on the master-slave switching data.
[0035] The end log is a newly added end event log in the embodiment of the present disclosure, which is used as the last log in the target master database. The end log can be understood as a log representing the end, and the log content can be empty.
[0036] Specifically, after the consistency component corresponding to the target slave database receives the master-slave switching data, an end log may be generated to replace the position of the master-slave switching data. The end log may be located at the end of the target log, and the data format is a format that the database can recognize.
[0037] Since the master-slave switching data is generated by the data replication module and cannot be recognized by the database, the consistency component can add an end log that can be recognized by the database as the last log of the target log after receiving the master-slave switching data.
[0038] Step 103: Send the end log and the target log to the target slave database, so that the target slave database is switched to the new master database based on the end log and the target log.
[0039] After the consistency component corresponding to the target slave database generates the end log, the end log and the target log can be sent to the target slave database. The target slave database receives the target log. After receiving the end log, since the end log is at the tail, it can be determined that the target log is received and the target slave database can be officially switched to the new master database.
[0040] In the disclosed embodiment, the end log and the target log are sent to the target slave database, so that the target slave database switches to the new master database after determining that the target log is received based on the end log, including: by calling the log transmission thread and the database language thread, the end log and the target log are sent to the target slave database, so that the target slave database updates the master-slave attribute information after determining that the target log is received based on the end log, and switches to the new master database. The log transmission (IO) thread and the database language (Structured Query Language, SQL) thread only exist in the target slave database instance, the log transmission thread is a thread for receiving database logs, and the logs received by the log transmission thread are all logs that can be identified inside the database, and the database language thread is a thread for redoing logs.
[0041] The consistency component can send the end log and the target log to the target slave database by calling the log transmission thread. After receiving the end log, the target slave database can close the log transmission thread and call the database language thread to redo the log. Due to receiving the end log, the master-slave attribute information of the target slave database can be updated from slave to master, and the target slave database can be switched to the new master database to achieve master-slave switching. The master-slave attribute information can be the role information of the database, including master and slave role information.
[0042] The master-slave switching solution for a database provided by the disclosed embodiment is that the consistency component corresponding to the target slave database can receive the master-slave switching data and the target log, wherein the target log is the log of the target master database; generate an end log based on the master-slave switching data; and send the end log and the target log to the target slave database, so that the target slave database switches to the new master database based on the end log and the target log. With the above technical solution, before the master-slave switching is performed, the slave database can receive the end log generated by its corresponding consistency component, and determine the completion of log reception of the previous master database based on the end log, thereby realizing the master-slave role switching of the slave database to the new master database, thus avoiding the problem of untimely master-slave role switching due to the uncertainty of whether the log reception is complete in the prior art, and improving the efficiency of master-slave switching of database instances.
[0043] In some embodiments, before sending the end log and the target log to the target slave database, it also includes: after converting the master-slave switching data into data in a preset format, calling the control thread to send it to the target slave database, so that the target slave database starts the log transmission thread and the database language thread.
[0044] The consistency component corresponding to the target slave database can convert the master-slave switching data into data in a preset format through format conversion, and then call the control thread to send the converted data to the database, so that the database can start the log transmission thread and the database language thread for subsequent log transmission and execution. Among them, the preset format is a data format that the database can recognize. By calling the control thread to send the master-slave switching data after the conversion format, the database can be prepared to receive logs and improve the efficiency of log transmission.
[0045] Figure 2 This is a flow chart of another master-slave switching method of a database provided by an embodiment of the present disclosure. Based on the above embodiment, this embodiment further optimizes the master-slave switching method of the above database. Figure 2 As shown, the method includes:
[0046] Step 201: Receive master-slave switching data and target log sent after a target master database fails.
[0047] The target log is the log of the target master database. The target slave database is the historical slave database that is about to be switched to the new master database, and the target master database is the historical master database that is about to be switched to the new slave database.
[0048] The master-slave switching data stores a database identifier of the slave database switching to the master database and a database identifier of the master database switching to the slave database, and the master-slave switching data is located at the tail of the target log.
[0049] Step 202: Generate an end log based on the master-slave switching data.
[0050] The end log is located at the end of the target log and supports database identification.
[0051] Step 203: After converting the master-slave switching data into data in a preset format, the control thread is called to send the data to the target slave database, so that the target slave database starts a log transmission thread and a database language thread.
[0052] Step 204: Send the end log and the target log to the target slave database, so that the target slave database is switched to the new master database based on the end log and the target log.
[0053] Specifically, the end log and the target log are sent to the target slave database so that the target slave database switches to the new master database after determining that the target log is received based on the end log, including: sending the end log and the target log to the target slave database by calling the log transmission thread and the database language thread, so that the target slave database updates the master-slave attribute information and switches to the new master database after determining that the target log is received based on the end log.
[0054] Next, a specific example is used to specifically illustrate the master-slave switching method of the database provided by the embodiment of the present disclosure. For example, Figure 3 A log transmission diagram of a database provided in an embodiment of the present disclosure is shown in FIG. Figure 3 , the log transmission process may include: the master database instance may send the database log generated by the master database (not shown in the figure) to the slave database instance through the data replication module; the data replication module in the slave database instance may send the received database log to the corresponding consistency component; the consistency component calls the log transmission thread and the database language thread to send the database log to the slave database (not shown in the figure). The value of the read-only field (Read only) of the master database is false (False), indicating that read and write requests can be accepted, and the value of the read-only field of the slave database is true (True), indicating that only read requests can be accepted.
[0055] Figure 3 The control information refers to the master-slave switching data. The Acknowledge character (ACK) is the information returned by the slave database instance to indicate that the log has been successfully received. After the target master database instance receives the confirmation characters of all slave database instances through the consistency component, it can execute Figure 3 In the phase 0 to phase 3, the database writes the database log to the local disk. Phase 0 to phase 3 represent consistency, flush, sync, and commit respectively.
[0056] The database log is sent from the master database to the slave database in the form of a pipeline. The log may be in all the positions marked in the figure. In order to enable the slave database to determine the completion of log reception in time and then realize role switching, an end log is added in the embodiment of the present disclosure to realize master-slave switching.
[0057] For example, Figure 4 A schematic diagram of a master-slave switch of a database provided in an embodiment of the present disclosure, Figure 4 Only the consistency component of the target slave database instance is improved, and the other processes are the same as Figure 3 The process shown in is the same. Figure 4After the consistency component in the target slave database instance receives the master-slave switching data and the log of the target master database sent by the data replication module, it can be determined that the election is successful and an end log is generated based on the master-slave switching data; by calling the log transmission thread and the database language thread, the end log and the log of the target master database are sent to the target slave database, so that the target slave database determines that the target log reception is completed based on the end log, updates the master-slave attribute information of the target slave database, and sets the value of the read-only field to false; the user can connect to the new master database instance after the master-slave switching and execute read and write requests to the new master database.
[0058] Figure 4 The control information in Figure 3 The control information in has the same meaning, and also represents the master-slave switching data. When the slave database does not receive the end log through the log transmission thread, it means that it has not been elected successfully, or it has been elected successfully but the logs of the target master database have not been received. You can wait normally and receive the logs.
[0059] The newly added end log in the embodiment of the present disclosure does not have any loss. Since the consistency component is responsible for generating the end log and sending the end log to the database through a special queue, this process is the logic of ordinary memory reading and writing, and does not go through the network transmission. There is no end log loss, which ensures the timeliness and accuracy of determining the completion of log transmission.
[0060] The master-slave switching solution for a database provided by an embodiment of the present disclosure is that the consistency component corresponding to the target slave database can receive the master-slave switching data and the target log sent after the target master database fails; generate an end log based on the master-slave switching data; and send the end log and the target log to the target slave database, so that the target slave database switches to the new master database based on the end log and the target log. With the above technical solution, before the master-slave switching is performed, the slave database can receive the end log generated by its corresponding consistency component, and determine based on the end log that the log reception of the previous master database is complete, thereby realizing the master-slave role switching of the slave database and switching to the new master database, thereby avoiding the problem of untimely master-slave role switching due to the uncertainty of whether the log reception is complete in the prior art, and improving the efficiency of master-slave switching of database instances.
[0061] Figure 5 The schematic diagram of the structure of a master-slave switching device for a database provided by an embodiment of the present disclosure is shown in FIG. 1 , which can be implemented by software and / or hardware and can generally be integrated in an electronic device. Figure 5 As shown, the device is configured with a consistency component corresponding to the target slave database, including:
[0062] The data receiving module 301 is used to receive the master-slave switching data and the target log, wherein the target log is the log of the target master database;
[0063] An end log module 302, configured to generate an end log based on the master-slave switching data;
[0064] The master-slave switching module 303 is used to send the end log and the target log to the target slave database, so that the target slave database is switched to a new master database based on the end log and the target log.
[0065] The master-slave switching solution for a database provided by the disclosed embodiment is that the consistency component corresponding to the target slave database can receive the master-slave switching data and the target log, wherein the target log is the log of the target master database; generate an end log based on the master-slave switching data; and send the end log and the target log to the target slave database, so that the target slave database switches to the new master database based on the end log and the target log. With the above technical solution, before the master-slave switching is performed, the slave database can receive the end log generated by its corresponding consistency component, and determine the completion of log reception of the previous master database based on the end log, thereby realizing the master-slave role switching of the slave database to the new master database, thus avoiding the problem of untimely master-slave role switching due to the uncertainty of whether the log reception is complete in the prior art, and improving the efficiency of master-slave switching of database instances.
[0066] Optionally, the master-slave switching data stores a database identifier of a slave database switching to a master database and a database identifier of a master database switching to a slave database, and the master-slave switching data is located at the end of the target log.
[0067] Optionally, the end log is located at the end of the target log.
[0068] Optionally, the master-slave switching module 303 is specifically used for:
[0069] By calling the log transmission thread and the database language thread, the end log and the target log are sent to the target slave database, so that the target slave database updates the master-slave attribute information after determining that the target log is received based on the end log, and switches to the new master database.
[0070] Optionally, the device further comprises a thread starting module, which is specifically used to: before sending the end log and the target log to the target slave database,
[0071] After the master-slave switching data is converted into data in a preset format, a control thread is called to send the data to the target slave database, so that the target slave database starts the log transmission thread and the database language thread.
[0072] Optionally, the data receiving module 301 is specifically used for:
[0073] Receive the master-slave switch data and the target log sent after the target master database fails.
[0074] Optionally, the target slave database is a historical slave database that is about to be switched to a new master database, and the target master database is a historical master database to be switched to a new slave database.
[0075] The master-slave switching device for a database provided in the embodiment of the present disclosure can execute the master-slave switching method for a database provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.
[0076] Figure 6 The structure diagram of an electronic device provided by the embodiment of the present disclosure is shown in FIG. Figure 6 As shown, the electronic device 400 includes one or more processors 401 and a memory 402 .
[0077] The processor 401 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 400 to perform desired functions.
[0078] The memory 402 may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 401 may run the program instructions to implement the master-slave switching method of the database of the embodiment of the present disclosure described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.
[0079] In one example, the electronic device 400 may further include: an input device 403 and an output device 404, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0080] In addition, the input device 403 may also include, for example, a keyboard, a mouse, and the like.
[0081] The output device 404 can output various information to the outside, including the determined distance information, direction information, etc. The output device 404 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.
[0082] Of course, to simplify, Figure 6 Only some of the components related to the present disclosure in the electronic device 400 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 400 may also include any other appropriate components.
[0083] In addition to the above methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the master-slave switching method of the database provided by the embodiments of the present disclosure.
[0084] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0085] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the master-slave switching method of the database provided by the embodiment of the present disclosure.
[0086] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0087] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0088] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A master-slave switching method for a database, characterized in that: The method is applied to a consistency component corresponding to a target slave database, and includes: Receiving master-slave switching data and a target log, wherein the target log is a log of a target master database; Generate an end log based on the master-slave switching data; The end log and the target log are sent to the target slave database, so that the target slave database is switched to a new master database based on the end log and the target log.
2. The method according to claim 1, characterized in that The master-slave switching data stores a database identifier of a slave database switching to a master database and a database identifier of a master database switching to a slave database, and the master-slave switching data is located at the end of the target log.
3. The method according to claim 1, characterized in that: The end log is located at the end of the target log.
4. The method according to claim 1, characterized in that: Sending the end log and the target log to the target slave database so that the target slave database is switched to a new master database based on the end log and the target log, comprising: By calling the log transmission thread and the database language thread, the end log and the target log are sent to the target slave database, so that the target slave database updates the master-slave attribute information after determining that the target log is received based on the end log, and switches to the new master database.
5. The method according to claim 4, characterized in that Before sending the end log and the target log to the target slave database, the method further includes: After the master-slave switching data is converted into data in a preset format, a control thread is called to send the data to the target slave database, so that the target slave database starts the log transmission thread and the database language thread.
6. The method according to claim 1, characterized in that The receiving of master-slave switching data and target logs includes: Receive the master-slave switch data and the target log sent after the target master database fails.
7. The method according to claim 1, characterized in that The target slave database is a historical slave database that is about to be switched to a new master database, and the target master database is a historical master database that is to be switched to a new slave database.
8. A master-slave switching device for a database, characterized in that: The device is configured on a consistency component corresponding to a target slave database, including: A data receiving module, used for receiving master-slave switching data and a target log, wherein the target log is a log of a target master database; An end log module, used for generating an end log based on the master-slave switching data; The master-slave switching module is used to send the end log and the target log to the target slave database, so that the target slave database is switched to a new master database based on the end log and the target log.
9. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the master-slave switching method of the database described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the master-slave switching method of the database as described in any one of claims 1 to 7.
