Database processing method and device, electronic equipment, storage medium and product

By selecting the slave database based on multiple filter conditions when the master database fails, and reselecting the master database according to the storage location, the problem of low accuracy in selection of slave databases is solved, data integrity and system stability are improved, and the repair process is simplified , enhances the success rate of automated switching.

CN119149307APending Publication Date: 2024-12-17MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410746411.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

When the master database fails, the accuracy of selection of the slave database is low, resulting in data loss and incompleteness, resulting in inconsistency between master and slave data. The new database system has the risk of instability, and manual repair is difficult after the automatic switching fails. .

Method used

In the event of a primary database failure, select candidate primary databases from multiple slave databases based on multiple filtering conditions (such as no replication filter parameters exist, normal operation, synchronization site is above threshold, binary log format and database parameter configuration). Improve the accuracy of selection through comprehensive filtering conditions, and reselect the candidate primary database closest to the primary database according to the storage location after replacing the primary database.

Benefits of technology

It improves the accuracy of selection from the database when the master database fails, enhances data integrity and system stability, reduces the risk of data loss, simplifies the manual repair process, and improves the success probability and business continuity of automated handovers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149307A_ABST
    Figure CN119149307A_ABST
Patent Text Reader

Abstract

The invention provides a database processing method and device, electronic equipment, a storage medium and a product. The method comprises the steps that if a main database in a database system breaks down, candidate main databases are selected from M slave databases of the database system based on N screening conditions, and T candidate main databases are obtained; wherein N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1; and replacing the main database with a target candidate main database in the T candidate main databases. Through the method and the device, the accuracy of selecting the slave database under the condition that the master database fails can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a database processing method, device, electronic device, storage medium and product. Background Art

[0002] In a database system, when a master database fails, all slave databases are usually screened according to the set master election conditions to select a slave database that can replace the master database. However, the master election conditions commonly used in related technologies are relatively simple, resulting in low accuracy in the selected slave databases. Summary of the invention

[0003] The embodiments of the present application provide a database processing method, device, electronic device, storage medium and product, which can improve the accuracy of selecting from a database when a main database fails.

[0004] The technical solution of the embodiment of the present application is implemented as follows:

[0005] The present application provides a method for processing a database, the method comprising:

[0006] If a master database in the database system fails, based on N screening conditions, candidate master databases are selected from M slave databases in the database system to obtain T candidate master databases; wherein both N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1;

[0007] The target candidate primary database among the T candidate primary databases replaces the primary database.

[0008] The present application provides a database processing device, including:

[0009] A selection module, configured to select a candidate primary database from M slave databases of the database system based on N screening conditions to obtain T candidate primary databases if a primary database in the database system fails; wherein both N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1;

[0010] A replacement module is used to replace the master database with a target candidate master database among the T candidate master databases.

[0011] An embodiment of the present application provides an electronic device, the electronic device comprising:

[0012] A memory for storing computer executable instructions;

[0013] The processor is used to implement the database processing method provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.

[0014] An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing a database processing method provided in an embodiment of the present application when executed by a processor.

[0015] An embodiment of the present application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, the database processing method provided in the embodiment of the present application is implemented.

[0016] The embodiments of the present application have the following beneficial effects:

[0017] If a master database in a database system fails, a candidate master database is selected from M slave databases of the database system based on N screening conditions to obtain T candidate master databases; the candidate master database can be selected more accurately through multiple screening conditions, wherein N and M are both integers greater than or equal to 2, and T is an integer greater than or equal to 1; a target candidate master database is determined from the T candidate master databases; and the selection of slave databases by combining multiple screening conditions can improve the accuracy of slave database selection when the master database fails. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a schematic diagram of the architecture of the database processing system provided in the embodiment of the present application;

[0019] Figure 2 is a schematic diagram of the structure of an electronic device for implementing a database processing method provided in an embodiment of the present application;

[0020] Figure 3 It is a flowchart of a method for processing a database provided in an embodiment of the present application;

[0021] Figure 4 It is a schematic diagram of the database system fault recovery process provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0023] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0024] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0025] In the embodiments of the present application, the terms "module" and "unit" refer to a computer program or a part of a computer program with a predetermined function, and work together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0026] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as those commonly understood by those skilled in the art. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.

[0027] The relevant data collection and processing in the embodiments of this application should be strictly in accordance with the requirements of relevant national laws and regulations when applied in examples, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of authorization of laws and regulations and the personal information subject.

[0028] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0029] 1) Master database (abbreviated as master database) is a key term in database management system, which is used to describe the architecture and management mode of the database. The master database is usually the central node of the database system, responsible for handling all read and write requests. It keeps the latest copy of the data and regularly replicates the changes to the slave database. The master database is usually the entity responsible for managing the integrity and consistency of the data. For example, in a banking system, the master database may contain customer account information, transaction history, and other key data.

[0030] 2) Slave database (slave database for short) is a key term in database management systems, which is used to describe the architecture and management mode of the database. The slave database is a replicated instance of the master database, which receives updated data from the master database and updates its own copy of the data when necessary. Slave databases are generally used to provide high availability, load balancing, and failover capabilities. It is a standby node for reading data, and when the master database fails, the slave database can take over the service. For example, in a banking system, a slave database can be used to provide access to branches or remote offices to ensure data consistency and availability. When the master database fails, the slave database can quickly take over and restore services to ensure that business operations are not affected.

[0031] 3) Storage location refers to the storage location of the database, which depends on the architecture and configuration of the database system. In a database system, the slave database is usually stored in the same or different physical location as the master database.

[0032] 4) Replication filtering refers to the process of limiting, screening or filtering the data or operations to be replicated during the database replication process. Through replication filtering parameters, database administrators can selectively replicate certain tables, specific rows or columns, or exclude certain data to meet the needs of different environments. For example, in an enterprise's database system, the master database may contain tables such as customer information, order data, and product information. In the case where only a specific department needs it, only the customer information table and order data table need to be copied in the slave database, and there is no need to copy the product information table. Through replication filtering parameters, it is possible to copy only part of the data, reduce the storage and network transmission pressure of the slave database, and ensure the synchronization and consistency of the required data.

[0033] 5) Replication status refers to the status information of each component or step in the database replication process, including whether the replication task is running, whether the replication is successful, whether any errors occur, replication filtering, etc. The replication status is usually provided by database replication management tools, which can provide real-time status monitoring and logging to help administrators understand the current status and performance of the replication process. For example, in a database replication system, the replication task between the master database and the slave database may be affected by network problems, database performance, or system failures. By monitoring the replication status, the administrator can understand whether the replication task is running, whether any errors occur, and whether the replication is successful.

[0034] 6) Operation status refers to the current working status of the slave database, providing information about the data synchronization status, replication delay, error information, etc. between the slave database and the master database. For example, the operation status of the slave database is one of the important indicators to measure whether the system or device is working normally during the master-slave replication and master-slave switching process, which can help users or administrators to find and solve problems in time and improve the stability and performance of the system.

[0035] 7) Synchronization point, usually refers to a specific mark or position used to identify the consistency point in the database or the synchronization status of a transaction. Synchronization point plays a key role in the database system to ensure data consistency and reliability. For example, in a database replication and high availability environment, it indicates the current data replication position of the slave database on the master database. When the slave database is replicated to a specific synchronization point, it means that the slave database has been consistent with the master database data.

[0036] 8) Thread refers to a lightweight process used within a database management system to perform concurrent operations, handle requests and tasks. For example, SQL threads refer to threads used to execute SQL statements within a database management system. These threads are specifically responsible for receiving SQL requests from clients, parsing SQL statements, executing query plans, accessing data in the database, and returning results. SQL threads are a key part of a database system for handling concurrent requests, and they help database management systems improve performance and responsiveness. I / O threads refer to threads within a database management system that are specifically responsible for performing input and output operations. These threads are mainly responsible for managing the database's disk I / O activities, such as reading data files, index files, log files, etc., and writing updated data and indexes.

[0037] 9) Relay log refers to the log file used to transmit the contents of the binary log file on the master database in the MySQL database replication mechanism. When using a slave database, the binary log file will be copied from the master database, the copied contents will be recorded in the relay log file, and then these operations will be applied to the local database. For example, suppose there is a master-slave replication MySQL database architecture, where the master database is A and the slave database is B. When an update operation is performed on the master database A, the operation will be recorded in the binary log file. The slave database B copies the operation from the binary log file of the master database A to its own relay log file, and then applies this operation to its own database. In this way, the data of the slave database B will be synchronized with the master database A to ensure data consistency.

[0038] 10) Binary log format is a way for database systems to record and track changes in the database. It records database changes in binary form and is usually used in scenarios such as data recovery, fault recovery, and data synchronization. There are usually the following binary log formats: 1. Standard binary log format: The default format in MySQL, which records all data change operations, including inserts, updates, and deletes. The standard binary log format provides a complete record of data changes, which is convenient for data recovery and master-slave replication. For example: In MySQL, the binary log file of each table usually has the suffix "binlog", such as "mysql-bin.000001". Open this file and you can see that each line in it records each data change operation. 2. Row format: Based on row records, it records each data change operation. It not only records the row data before and after the change, but also records detailed information such as the row ID and column value of each row of data. The row format is suitable for some large database systems and can track the changes of each row of data more accurately. In MySQL, you can use the "--binlog-row-format=ROW" option to enable the row format binary log. By viewing the binary log file in row format, you can see that each row records the specific row data changes. In addition to the above two formats, binary logs can also use other formats, such as statement format and mixed format. Each format has its specific uses and advantages and disadvantages, and you need to choose the appropriate format according to the specific application scenario.

[0039] 11) Parameters refer to database parameters, which are setting options used to configure the behavior and performance of the database system. You can adjust the operation mode of the database and optimize performance by modifying the parameter values. Different database systems have different parameters for controlling various aspects of operations and optimization. For example, "sync_binlog" (a parameter that controls the frequency of binary log synchronization to disk) is used to control the synchronous writing behavior of the binary log. The binary log records the database change operations. When the database performs a write operation, the system will write the change operation to the binary log. The value of the sync_binlog parameter is 0, 1, or N, indicating different synchronous writing behaviors: 0: Indicates that the binary log write operation will not be synchronized to the disk, but the operating system controls when to write the data to the disk; this setting will improve the write performance, but may cause the risk of data loss. 1: Indicates that each write operation needs to wait for the binary log to be written to the disk before completing the operation, ensuring the persistence of the write disk operation, but it will reduce the write performance. N: Indicates that the binary log will be synchronized to the disk every N write operations, which can reduce the frequency of disk synchronization while ensuring performance.

[0040] "innodb_flush_log_at_trx_commit" (parameter for the storage engine to refresh the log when the transaction is committed) is a parameter of the storage engine (InnoDB) that controls the writing behavior of the transaction log. InnoDB is a storage engine of MySQL that is used to process transactional data and ensures the atomicity, consistency, and durability of transactions through transaction logs. The value of this parameter is 0, 1, or 2, and the specific meanings are as follows: 0: It means that when the transaction is committed, the transaction log will not be forced to be written to the disk, but the system will automatically decide the appropriate time to write it; the performance is optimal, but data loss may occur. 1: It means that when the transaction is committed, the transaction log will be synchronized to the disk immediately; the persistence of the transaction is ensured, but the performance will be reduced. 2: It means that when the transaction is committed, the transaction log will be written to the disk, and the data pages in the buffer pool will also be refreshed at the same time; the performance is slightly lower than 1, but it will improve some I / O efficiency.

[0041] 12) Database properties refer to the read and write properties of the database.

[0042] 13) System topology refers to the method used to describe the connection and structure between various databases in a database system.

[0043] During the research, the applicant found that when a master database in a database system fails, a single screening condition is usually used to select a slave database from a number of slave databases to replace the failed master database during the fault recovery work, thereby completing the fault switch and providing database services. In the actual application process of the relevant technology, there are still the following technical problems:

[0044] 1. When the primary database fails, the accuracy of the secondary database selection is low;

[0045] 2. Data is easily lost and incomplete, resulting in inconsistency between master and slave data;

[0046] 3. The new database system has the risk of instability;

[0047] 4. After the automatic switching of the database system fails, manual repair is difficult.

[0048] The embodiments of the present application provide a method, device, electronic device, storage medium and product for processing a database, which can improve the accuracy of selecting from a database when a main database fails. The following describes an exemplary application of the electronic device provided by the embodiments of the present application. The electronic device provided by the embodiments of the present application can be implemented as various types of terminals such as laptop computers, tablet computers, desktop computers, set-top boxes, smart phones, smart speakers, smart watches, smart TVs, and vehicle-mounted terminals, and can also be implemented as servers. The following describes an exemplary application of the database processing system provided by the embodiments of the present application.

[0049] See also Figure 1 , Figure 1 It is a schematic diagram of the architecture of the database processing system provided in the embodiment of the present application. To support an application, in the system 10, the terminal 400 is connected to the server 200 via the network 300. The network 300 may be a wide area network or a local area network, or a combination of the two.

[0050] When a primary database in the database system 100 fails, the server 200 selects candidate primary databases from M secondary databases of the database system 100 based on N screening conditions to obtain T candidate primary databases, and replaces the primary database with a target candidate primary database among the T candidate primary databases.

[0051] The server 200 is further configured to send the selected target candidate master database to the terminal 400 .

[0052] The terminal 400 is used to receive the selected target candidate master database.

[0053] The graphical interface 410 is used to display the selected target candidate master database.

[0054] In some embodiments, the server 200 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal and the server may be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.

[0055] See also Figure 2 , Figure 2 is a schematic diagram of the structure of an electronic device for implementing a database processing method provided in an embodiment of the present application. The electronic device may be a terminal or a server. Figure 2 The electronic device 500 shown includes: at least one processor 510, a memory 550, at least one network interface 520 and a user interface 530. The various components in the electronic device 500 are coupled together via a bus system 540. It is understood that the bus system 540 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 540 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 540 is not described in detail. Figure 2 Various buses are labeled as bus system 540 .

[0056] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0057] The user interface 530 includes one or more output devices 531 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.

[0058] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disk drives, etc. The memory 550 may optionally include one or more storage devices that are physically remote from the processor 510.

[0059] The memory 550 includes a volatile memory or a nonvolatile memory, and may also include both volatile and nonvolatile memories. The nonvolatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 550 described in the embodiments of the present application is intended to include any suitable type of memory.

[0060] In some embodiments, the memory 550 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplarily described below.

[0061] Operating system 551, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;

[0062] A network communication module 552, used to reach other electronic devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 include: Bluetooth, Wireless Compatibility Certification (WiFi), and Universal Serial Bus (USB), etc.;

[0063] a presentation module 553 for enabling presentation of information via one or more output devices 531 (e.g., display screen, speaker, etc.) associated with the user interface 530 (e.g., a user interface for operating peripherals and displaying content and information);

[0064] The input processing module 554 is used to detect one or more user inputs or interactions from one of the one or more input devices 532 and translate the detected inputs or interactions.

[0065] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 2 The processing device 555 of the database stored in the memory 550 is shown, which can be software in the form of a program and a plug-in, etc., including the following software modules: a selection module 5551 and a replacement module 5552. These modules are logical, so they can be arbitrarily combined or further split according to the functions implemented. The functions of each module will be explained below.

[0066] In other embodiments, the database processing device provided in the embodiments of the present application can be implemented in hardware. As an example, the database processing device provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the database processing method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application specific integrated circuits (Application Specific Integrated Circuit, ASIC), digital signal processors (Digital Signal Processor, DSP), programmable logic devices (Programmable Logic Device, P LD), complex programmable logic devices (Complex Programmable Logic Device, CPLD), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other electronic components.

[0067] The database processing method provided by the embodiment of the present application will be described in conjunction with the exemplary application and implementation of the electronic device provided by the embodiment of the present application. As mentioned above, the electronic device implementing the database processing method of the embodiment of the present application can be a terminal, a server, or a combination of the two.

[0068] Taking the electronic device as a server as an example, the database processing method of the embodiment of the present application is described, see Figure 3 , Figure 3 is a flowchart of the database processing method provided in the embodiment of the present application, which will be combined with Figure 3Steps 101 to 102 are shown for explanation.

[0069] In step 101, if a master database in the database system fails, candidate master databases are selected from M slave databases in the database system based on N screening conditions to obtain T candidate master databases.

[0070] Wherein, N and M are both integers greater than or equal to 2, and T is an integer greater than or equal to 1.

[0071] In some embodiments, the architecture of the database system may be a MySQL master-slave architecture, a MySQL manager architecture (MySQL MGR architecture), a Percona XtraDB cluster architecture (Percona Xtra DB Cluster architecture), and the like.

[0072] In some embodiments, the orchestrator may be used to periodically detect whether a master database in the database system fails. High-availability switching tools or methods such as MMM (Multi-Master Replication Manager) and M HA (Master High Availability) may also be used to periodically detect whether a master database in the database system fails. This is not limited in the embodiments of the present application.

[0073] For example, the orchestrator tool is used to periodically detect whether a primary database named "MyDatabase" has failed. On the premise that the orchestrator has been correctly configured and can communicate with the MyDatabase primary database system, a new task is created in the orchestrator to detect the status of MyDatabase at 1 a.m. every day. A Python script can be used to connect to MyDatabase and execute a simple query, such as querying the number of records in a table named "health_check". When the result returned by the detection script at 1 a.m. on a certain day indicates that the number of records in the "health_check" table is 0, it means that MyDatabase may have failed. Orchestrator can automatically perform fault recovery, or it can send warning notifications to relevant technical personnel according to preset rules. After the fault is repaired, rerun the detection task to ensure that MyDatabase has returned to normal.

[0074] In some embodiments, the N filtering conditions may include at least two of the first filtering condition, the second filtering condition, the third filtering condition, the fourth filtering condition and the fifth filtering condition, such as including the first filtering condition, the second filtering condition and the third filtering condition.

[0075] In some embodiments, the N screening conditions include a first screening condition, the first screening condition is used to indicate screening of slave databases that do not have a replication filter parameter. Figure 3 The "based on N screening conditions, selecting candidate master databases from M slave databases of the database system to obtain T candidate master databases" in step 101 can be implemented by the following technical solution: according to the first screening condition, selecting a slave database without replication filtering parameters from the M slave databases as a candidate master database.

[0076] In the database system, MySQL supports filtering certain databases or tables during the master-slave replication process and not replicating them. This function can be achieved by setting replication filtering parameters, thereby improving replication efficiency, avoiding unnecessary data synchronization, and controlling the replication scope of data. Specifically, the replication filtering parameters can be set in the configuration file of the slave server, so that the data replicated from the master database by the slave database with the replication filtering parameters is incomplete.

[0077] As an example, the replication status of each of the M slave databases may be obtained by executing a command for displaying the slave database replication status, and whether the slave database has a replication filter parameter may be checked from the replication status.

[0078] For example, the command to display the replication status of the slave database can be "show slave status\G". The "show slave status\G" command can be used to view the replication status of the slave database, including whether replication is in progress, the replication delay, and the replication filter settings. This command returns detailed replication-related information, including replication filter parameters.

[0079] According to the first screening condition, a slave database without replication filter parameters is selected from the M slave databases as a candidate master database. For example, by executing the "show slave status\G" command, it is checked whether the database replication filter parameters "Replicate_Do_DB (replicate the specified database), Replicate_Ignore_DB (ignore replication of the specified database), Replicate_Do_Table (replicate the specified table), Replicate_Ignore_Table (ignore replication of the specified table), Replicate_Wild_Do_Table (wildcard replication of the specified table), Replicate_Wild_Ignore_Table (wildcard mode ignores replication of the specified table), and Replicate_Rewrite_DB (rewrite the database name used in the statement)" exist in the slave database replication status, and the slave database without any of these parameters is selected as a candidate master database.

[0080] Through the above technical solution, a slave database without replication filtering parameters can be selected as a candidate master database, thereby improving data integrity.

[0081] In some embodiments, the N screening conditions include a second screening condition, and the second screening condition is used to indicate screening of slave databases in a normal operating state. Figure 3 The "based on N screening conditions, selecting candidate master databases from M slave databases of the database system to obtain T candidate master databases" in step 101 can be implemented by the following technical solution: according to the second screening condition, selecting a slave database in normal operation from the M slave databases as a candidate master database.

[0082] As an example, according to the identifier corresponding to the running status (the running status of each slave database in the database system can be labeled as an identifier), the running status of each slave database in the M slave databases is obtained (the running status can be set by combining scheduled monitoring, dynamic update and active setting), and the running status of the slave database can be set to downtime due to hardware maintenance or other reasons. For example, if the slave database in the downtime state is used as the new master database without considering whether the candidate master database is in a normal running state, the new database system will be in an unstable state.

[0083] As an example, according to the running status of M slave databases, the slave databases in the downtime status are excluded, and the slave databases in the normal running status are selected as the candidate master databases.

[0084] Through the above technical solution, a slave database in normal operation can be selected as a candidate master database, thereby improving the stability of the new database system.

[0085] In some embodiments, the N screening conditions include a third screening condition, and the third screening condition is used to indicate screening of slave databases whose synchronization positions are higher than a synchronization position threshold. Figure 3 The "based on N screening conditions, selecting candidate master databases from M slave databases of the database system to obtain T candidate master databases" in step 101 can be implemented by the following technical solution: in response to the end of the thread replaying the relay log, according to the third screening condition, select a slave database whose synchronization point is higher than the synchronization point threshold from the M slave databases as a candidate master database.

[0086] As an example, binlog is an important log file in the MySQL database, which is used to record all changes to the database table. The relay log is the core part of the MySQL replication process, which is used to transmit change operations between the master and slave databases. For example, in the master-slave replication process, the master database records data changes (changes include but are not limited to inserting, updating, deleting records, etc.) in the binlog; the slave database reads the binlog events from the master database through the I / O thread; the I / O thread writes the read binlog events to the relay log of the slave database; the slave database executes the events in the relaylog through the SQL thread, thereby applying the changes of the master database on the slave database to maintain data consistency with the master database. Therefore, in order to improve the master-slave data consistency, before screening the candidate master database, it is necessary to wait for the SQL thread to finish replaying the relay log.

[0087] As an example, after waiting for the SQL thread to finish replaying the relay log, the synchronization position of each of the M slave databases can be obtained by executing the slave database synchronization position acquisition command. For example, the slave database synchronization position acquisition command can be the "show slave status\G" command. The "show slave status\G" command returns detailed replication-related information, including synchronization position information.

[0088] For example, you can get the values ​​of "Master_Log_File" (master log file) and "Read_Master_Log_Pos" (read master log position) of M slave databases by executing the "show slave status\G" command. "Master_Log_File" indicates the name of the binary log file that the master database is currently writing. It usually ends with a number, such as mysql-bin.000001. "Read_Master_Log_Pos" indicates the position of the master database binary log that the slave database is reading, that is, the position of the binary log that has been copied and applied to the slave database. "Read_Master_Log_Pos" is a number that indicates the offset in the master database binary log file, such as "1234567". If the "Master_Log_Fil e" of a slave database is mysql-bin.000001, and "Read_Master_Log_Pos" is "1234567", it means that the slave database has copied and applied all log operations before 1234567 bytes in the mysql-bin.000001 file of the master database.

[0089] For example, you can also get the values ​​of "Relay_Log_File" (relay log file) and "Relay_Log_Pos" (relay log position) of M slave databases by executing the "show slave status\G" command. "Relay_Log_File" indicates the name of the relay log file currently being applied by the slave database. Relay log files usually start with "relay-log" followed by a number, such as "relay-log.000002". "R elay_Log_Pos" indicates the current reading position of the slave database in the relay log file, that is, the position of the transaction that has been copied and applied to the slave database. "Relay_Log_Pos" is a number that indicates the byte offset in the relay log file, such as "1048576". If the "Relay_Log_File" of a slave database is "relay-log.000002" and "Relay_Log_Pos" is "1048576", it means that the relay log file being applied by the slave database is "relay-log.000002" and the current read position in the relay log file is 1048576 bytes. That is, the slave database has copied and applied all transactions before the 1048576th byte in the master database binary log "relay-log.000002".

[0090] For example, you can also enable the global transaction identifier (GTID), and then execute the "show slave status\G" command to get the values ​​of "Executed_Gtid_Set" (the set of GTIDs that have been executed) and "Retrieved_Gtid_Set" (the set of GTIDs that have been received from the master database) of M slave databases. "Executed_Gtid_Set" contains the set of GTIDs that have been executed by the slave database, that is, the list of transactions that have been applied to the database by the slave database, such as "GTID_1, GTID_2, and GTID_3". "Retrieved_Gtid_Set" contains the set of GTIDs that the slave database has received from the master database, that is, the list of transactions that have been submitted on the master database but have not yet been executed by the slave database, such as "GTID_1, GTID_2, GTID_3, and GTID_4".

[0091] As an example, compare the values ​​of "Master_Log_File" of each slave database, select the slave database with the largest value of "Master_Log_File", and then compare the value of "Read_Master_Log_Pos" of the slave database with the largest value of "Master_Log_File" with the preset synchronization point threshold. The value of "Read_M aster_Log_Pos" is greater than the synchronization point threshold, indicating that the synchronization point of the slave database is higher than the synchronization point threshold.

[0092] As an example, you can also compare the value of "Relay_Log_File" of each slave database and select the slave database with the largest value of "Relay_Log_File", and then compare the value of "Relay_Log_Pos" of each slave database with the largest value of "Relay_Log_File" with the preset synchronization position threshold. If the value of "Relay_L og_Pos" is greater than the synchronization position threshold, it means that the synchronization position of the slave database is higher than the synchronization position threshold.

[0093] As an example, you can also compare the values ​​of "Executed_Gtid_Set" of each slave database, select the slave database with the largest value of "R elay_Log_File", and then compare the value of "Retrieved_Gtid_Set" of each slave database with the largest value of "Executed_Gtid_Set" with the preset synchronization site threshold. If the value of "Retrieved_Gtid_Set" is greater than the synchronization site threshold, it means that the synchronization site of the slave database is higher than the synchronization site threshold.

[0094] As an example, the synchronization point threshold can be set according to actual conditions. For example, the synchronization point threshold can be set to the latest binary log point of the master database, thereby selecting the slave database that has applied the latest binary log point of the master database.

[0095] Through the above technical solution, a slave database whose position of the binary log of the master database has been applied and is higher than the synchronization position threshold can be selected to avoid data loss to the greatest extent and improve the consistency of master-slave data.

[0096] In some embodiments, the N filter conditions include four filter conditions, the fourth filter condition is used to indicate filtering the slave database whose binary log format is the target format, Figure 3 In step 101 shown, "based on N screening conditions, selecting a candidate master database from M slave databases of the database system to obtain T candidate master databases" can be implemented by the following technical solution: according to the fourth screening condition, selecting a slave database whose binary log format is the target format from the M slave databases as a candidate master database.

[0097] As an example, by executing an SQL statement to query the binary log format of a slave database, the value of the format parameter (binlog_format parameter) for specifying the binary log recording event of each slave database is retrieved from the database server. The binlog_format parameter indicates the binary log format of the slave database. Common binlog_format values ​​include STATEMENT, ROW, and MIXED. Among them, the slave database in ROW format can record the change information of each data, which can improve the consistency of master-slave data, has good compatibility with different database engines and versions, and can better support operations such as data recovery and data auditing.

[0098] As an example, the target format is ROW format. According to the values ​​of binlog_format parameters of M slave databases, a slave database whose binlog_format parameter is ROW is selected as a candidate master database.

[0099] It should be noted that if all slave databases are not in ROW format, the fault handling process can still continue, but there will be certain risks. From the perspective of the stability of the new database system, warnings must be issued and inspections and rectifications must be carried out in a timely manner.

[0100] Through the above technical solution, a slave database whose binary log format is ROW format can be selected to further improve the consistency of master-slave data.

[0101] In some embodiments, the N screening conditions include a fifth screening condition, the fifth screening condition is used to indicate the target parameter in the screening database parameter as a secondary database of the target value, Figure 3 The "based on N screening conditions, selecting candidate master databases from M slave databases of the database system to obtain T candidate master databases" in step 101 can be implemented by the following technical solution: according to the fifth screening condition, selecting a slave database with a target parameter in the database parameter as a target value from the M slave databases as a candidate master database.

[0102] As an example, by executing an SQL statement to query the parameters of the slave database, the values ​​of the target parameters "sync_binlog" (a parameter that controls the frequency of binary log synchronization to disk) and "innodb_flush_log_at_trx_commit" (a parameter for the storage engine to refresh logs when a transaction is committed) of each slave database are retrieved from the database server. The value of the "sync_binlog" parameter is 0, 1, or N, and the value of the "innodb_flush_log_at_trx_commit" parameter is 0, 1, or 2. Among them, "sync_binlog" is set to 1, which means that each time a transaction is committed, the data in the binlog cache will be synchronized to the disk, and the data security is high. "innodb_flush_log_at_trx_commit" is set to 1, which means that each time a transaction is committed, the data in the log buffer of the innodb storage engine will be written to the log file, and a flush operation will be performed to ensure the persistence of the transaction.

[0103] As an example, the target value of the target parameter is 1. According to the values ​​of the "sync_binlog" parameter and the "innodb_flush_log_at_trx_commit" parameter of M slave databases, the slave databases whose target parameter values ​​are all 1 are selected as candidate master databases.

[0104] It should be noted that if both parameters are set to 1, data security and durability can be improved, and the risk of data loss can be reduced. If both parameters are not set to 1, the fault handling process can still proceed, but there will be certain risks. From the perspective of the stability of the new database system, warnings and inspections should be issued in a timely manner to rectify the situation.

[0105] Through the above technical solution, a slave database whose "sync_binlog" parameter and "innodb_flush_log_at_trx_commit" parameter are both 1 can be selected, so as to persist the data, prevent data loss, and improve data persistence and security.

[0106] Continue to see Figure 3 , and the description will continue with step 101 above.

[0107] In step 102, a target candidate primary database among the T candidate primary databases replaces the primary database.

[0108] In some embodiments, the target candidate primary database can be selected by the following technical solution: determine the probability of each candidate primary database being selected as the target candidate primary database under N screening conditions; and determine the target candidate primary database from T candidate primary databases based on the probability.

[0109] As an example, the above determination of the probability of a candidate primary database being selected as a target candidate primary database under N screening conditions can be achieved through the following technical solution: according to the weight corresponding to each screening condition and the score of the candidate primary database under each screening condition, the probability of the candidate primary database being selected as the target candidate primary database under the N screening conditions is determined.

[0110] As an example, the weights corresponding to the N screening conditions can be set according to the actual situation. For example, the weights corresponding to the N screening conditions can be set to be the same, or different weights can be set according to the priorities of the screening conditions. The priority corresponding to each screening condition can be prioritized according to the actual situation.

[0111] The following example illustrates that, for example, N filtering conditions may include the first filtering condition, the second filtering condition, the third filtering condition, the fourth filtering condition and the fifth filtering condition. The following priorities can be set: the first filtering condition (A)> the second filtering condition (B)> the third filtering condition (C)> the fourth filtering condition (D)> the fifth filtering condition (E). The weight corresponding to each filtering condition is obtained according to the priority: A>B>C>D>E.

[0112] The first score for a slave database to be selected as a candidate master database under each screening condition and the second score for a slave database not to be selected as a candidate master database can be set according to actual conditions.

[0113] As an example, according to the weight corresponding to each screening condition and the score of the candidate primary database under each screening condition, the sum result of the candidate primary database is obtained; according to the sum result of the candidate primary database, the probability of the candidate primary database being selected as the target candidate primary database under N screening conditions is determined.

[0114] For example, the weight corresponding to each screening condition is multiplied by the score of the candidate primary database under each screening condition to obtain the multiplication results, and then the multiplication results are summed to obtain the target score as the summation result. The following example illustrates that, for example, N screening conditions may include the first screening condition, the second screening condition, the third screening condition, the fourth screening condition and the fifth screening condition. The candidate primary database is selected as the candidate primary database under the first screening condition, the second screening condition and the third screening condition, but is not selected as the candidate primary database under the fourth screening condition and the fifth screening condition. Then the summation result of the candidate primary database can be expressed by the following expression:

[0115] S=A*a1+B*b1+C*c1+D*d2+E*e2 (1)

[0116] Among them, S is the sum of the candidate master database selected as the target candidate master database under N screening conditions, A is the weight of the first screening condition, a1 is the first score of the candidate master database selected as the candidate master database under the first screening condition, B is the weight of the second screening condition, b1 is the first score of the candidate master database selected as the candidate master database under the second screening condition, C is the weight of the third screening condition, c1 is the first score of the candidate master database selected as the candidate master database under the third screening condition, D is the weight of the fourth screening condition, d2 is the second score of the candidate master database not selected as the candidate master database under the fourth screening condition, E is the weight of the fifth screening condition, and e2 is the second score of the candidate master database not selected as the candidate master database under the fifth screening condition. According to the actual situation, the first score of the candidate master database when it is selected by each screening condition and the second score when it is not selected can be set, wherein the first score can be recorded as 1 and the second score can be recorded as 0. The first score and the second score can also be set to other values, which are not limited in the embodiments of the present application.

[0117] Next, we calculate the maximum sum of candidate master databases, which can be expressed as follows:

[0118] S max =A*a1+B*b1+C*c1+D*d1+E*e1 (2)

[0119] Among them, S maxis the maximum sum result of the candidate primary database being selected as the target candidate primary database under N screening conditions, that is, it is selected as the candidate primary database under each screening condition, A is the weight of the first screening condition, a1 is the first score of the candidate primary database being selected as the candidate primary database under the first screening condition, B is the weight of the second screening condition, b1 is the first score of the candidate primary database being selected as the candidate primary database under the second screening condition, C is the weight of the third screening condition, c1 is the first score of the candidate primary database being selected as the candidate primary database under the third screening condition, D is the weight of the fourth screening condition, d1 is the first score of the candidate primary database being selected as the candidate primary database under the fourth screening condition, E is the weight of the fifth screening condition, and e1 is the first score of the candidate primary database being selected as the candidate primary database under the fifth screening condition.

[0120] The probability of calculating the candidate master database being selected as the target candidate master database under N screening conditions can be expressed as follows:

[0121]

[0122] Where P is the probability that the candidate master database is selected as the target candidate master database under N screening conditions, S is the sum of the candidate master databases selected as the target candidate master database under N screening conditions, and S max is the maximum sum of the candidate master databases selected as the target candidate master database under the N screening conditions. Finally, the candidate master database with the greatest probability is selected as the target candidate master database. It should be noted that if there are multiple candidate master databases with the same and maximum probability, a candidate master database is randomly selected from the multiple candidate master databases as the target candidate master database.

[0123] Through the above technical solution, a target candidate master database can be selected from the results of multiple screening conditions through a quantitative method, thereby improving the accuracy of slave database selection in the event of a master database failure.

[0124] In some embodiments, the target candidate primary database can be selected by the following technical solution: determine the number of times each candidate primary database is selected as a candidate primary database under N screening conditions; and determine the target candidate primary database from T candidate primary databases based on the number of times.

[0125] As an example, the number of times each candidate primary database is selected as a candidate primary database under N screening conditions is counted. For example, taking the N screening conditions as an example, which may include a first screening condition, a second screening condition, a third screening condition, a fourth screening condition, and a fifth screening condition, the candidate primary database is selected as a candidate primary database under the first screening condition, the second screening condition, and the third screening condition, but is not selected as a candidate primary database under the fourth screening condition and the fifth screening condition, then the number of times the candidate primary database is selected as a candidate primary database under the N screening conditions is 3.

[0126] The number of times corresponding to each candidate primary database is compared, and the candidate primary database with the highest number is determined as the target candidate primary database. When there are multiple candidate primary databases with the highest number, one candidate primary database is randomly selected to be determined as the target candidate primary database, or a secondary screening is performed according to the priority of the selected screening condition, such as selecting the screening condition with the highest priority. Assuming that the first screening condition has the highest priority, among multiple candidate primary databases with the highest number, the candidate primary database selected under the first screening condition is selected as the target candidate primary database.

[0127] Through the above technical solution, the target candidate master database can be selected according to the number of times the slave database is used as the candidate master data under each screening condition and the selection result of each screening condition can be integrated, thereby improving the accuracy of slave database selection in the event of a master database failure.

[0128] In some embodiments, the second replacement of the primary database can be achieved through the following technical solution: obtaining the storage locations of the target candidate primary database and the remaining candidate primary databases; based on the storage locations, if the target candidate primary database is not closest to the primary database, selecting a database closest to the primary database from the remaining candidate primary databases as a backup candidate primary database, and replacing the target candidate primary database with the backup candidate primary database as the new primary database.

[0129] As an example, the database settings and configurations may be queried to obtain geographic location information of the slave databases, and specific tools or methods may be used to obtain geographic location information about the slave databases, thereby obtaining the storage locations of the target candidate master database and the remaining candidate master databases.

[0130] According to the storage locations of the target candidate master database and the remaining candidate master databases, it is determined whether the target candidate master database is closest to the master database. If the target candidate master database is closest to the master database, no change is required.

[0131] Alternatively, it is determined whether the target candidate master database is in the same data center as the master database according to the storage location of the target candidate master database. If the target candidate master database is in the same data center as the master database, no change is required.

[0132] As an example, based on the storage locations of the target candidate primary database and the remaining candidate primary databases, determine whether the target candidate primary database is closest to the primary database. If the target candidate primary database is not closest to the primary database, select a database closest to the primary database from the remaining candidate primary databases as a backup candidate primary database. If there are multiple databases closest to the primary database selected from the remaining candidate primary databases, randomly select one of the remaining candidate primary databases as a backup candidate primary database, and use the backup candidate primary database as the new primary database to replace the target candidate primary database.

[0133] Alternatively, based on the storage location of the target candidate primary database, determine whether the target candidate primary database is in the same data center as the primary database. If the target candidate primary database is not in the same data center as the primary database, then based on the storage locations of the remaining candidate primary databases, select a database in the same data center as the primary database from the remaining candidate primary databases as a backup candidate primary database. If there are multiple databases in the remaining candidate primary databases that are in the same data center as the primary database, randomly select one of the remaining candidate primary databases as the backup candidate primary database, and use the backup candidate primary database as the new primary database to replace the target candidate primary database.

[0134] For example, the target candidate master database selected for the first time may be located in a remote computer room or another computer room in the same city, and is not in the same computer room as the original master database. The first master selection is mainly based on multiple screening conditions. Whether to conduct a second master selection can be determined based on the configuration options pre-defined by the user (for example, the candidate master database in the same data center (IDC) as the master database is preferred. If not, the candidate master database in another IDC in the same city is preferred). If a second master selection is required (a new candidate master database in the same IDC as the master database is selected), the topology architecture is reconstructed, the candidate new master database selected for the second time is replaced with the new candidate master database, and the master-slave replication synchronization relationship between the candidate master database selected for the first time and the remaining slave databases is changed to the new candidate master database (CHANGE MASTER TO master_host = 'best new master IP', master_port = best new master port, master_user = 'replication account', master_password = 'replication password', MASTER_AUTO_POSITION = 1;), and a new master-slave replication synchronization relationship is established.

[0135] Through the above technical solution, the candidate master database closest to the master database can be selected again according to the storage location of the database, thereby further improving the accuracy of selecting a slave database in the event of a master database failure.

[0136] In some embodiments, after the target candidate master database among the T candidate master databases replaces the master database, the database properties of the new master database and the corresponding slave databases can also be updated, which can be achieved through the following technical solution: the new master database cleans up the replication relationship between the new master database and the original master database and the replication relationship between the remaining slave databases and the original master database, establishes the replication relationship between the new master database and the remaining slave databases, and sets the new master database to a write-only state and the original master database to a read-only state.

[0137] The above technical solution can help complete fault switching and continue to provide online database services.

[0138] In some embodiments, Figure 3 The step 101 shown can also be implemented by the following technical solution: if the number of slave databases in normal replication status among the M slave databases reaches the target number, then based on N screening conditions, candidate master databases are selected from the M slave databases of the database system to obtain T candidate master databases.

[0139] As an example, the replication status of each slave database in M ​​slave databases can be obtained by executing a command to display the replication status of slave databases. For example, the command to display the replication status of slave databases can be the command "show slave status\G". When the number of slave databases in the M slave databases with normal replication status reaches When , based on the N screening conditions, candidate master databases are selected from the M slave databases of the database system to obtain T candidate master databases.

[0140] For example, if all M slave databases have replication anomalies, fault recovery cannot be performed and manual judgment and repair are required; if the database system has a one-master-two-slave architecture, there is a slave database replication anomaly and one slave database replication is normal, the slave database with normal replication can be used as a candidate master database. In the one-master-two-slave architecture, the condition for online switching is that at least one slave database's synchronous replication is normal; if the database system has one-master-three-slave, if more than half of the slave databases have abnormal replication, that is, there are problems with two nodes, which means that all slave databases have problems, then fault recovery cannot be performed.

[0141] It should be noted that if the number of slave databases in normal replication status among the M slave databases is less than the target number, the database system topology when the master database failure occurs is kept unchanged to facilitate subsequent manual repair.

[0142] Through the above technical solution, fault repair can be stopped by stopping the replication anomaly of the database. Even if the switch of the new master database is unsuccessful, it will not cause the system topology to change, which is convenient for manual repair. The ability to recover from the fault indicates that the replication of the database is normal, thereby improving the accuracy of selecting the slave database in the event of a master database failure.

[0143] In the embodiment of the present application, when a master database in a database system fails, a candidate master database can be selected from M slave databases of the database system based on N screening conditions to obtain T candidate master databases; multiple screening conditions can improve data integrity, stability of the new database system, master-slave data consistency, data persistence, and security; the target candidate master database selected based on multiple screening conditions can improve the accuracy of slave database selection in the event of a master database failure; after replacing the master database, the candidate master database closest to the master database can be reselected based on the storage location to replace the master database, further improving the accuracy of slave database selection in the event of a master database failure; before selecting a candidate master database for fault recovery, the replication status of all slave databases is checked, and when an abnormality is detected in the replication status of the slave database, fault recovery is stopped without changing the system topology, which is convenient for manual repair.

[0144] The following is an explanation of an exemplary application of the embodiments of the present application in a practical application scenario.

[0145] The embodiments of the present application are applicable to the MySQL master-slave architecture, and are also applicable to the MySQL MGR architecture and the PerconaXtraDB Cluster architecture.

[0146] The embodiment of the present application may use an orchestrator, and may also use high-availability switching tools or methods such as MMM (abbreviation for Multi-MasterReplication Manager) and MHA (abbreviation for Master High Availability) to perform fault detection on the database system.

[0147] See also Figure 4 , Figure 4 It is a schematic diagram of the database system fault recovery process provided in an embodiment of the present application.

[0148] like Figure 4 As shown, the following steps can be used to detect and recover database system failures:

[0149] In step 201, both the master database and the slave database may fail to be accessed. The orchestrator (database orchestration system 1, database orchestration system 2, database orchestration system 3) periodically detects whether the master database of the database system fails (for example, when the database orchestration system periodically detects the database system, the master database cannot be accessed, or the master database cannot access the slave database, etc.). If a failure of the master database is detected, the process goes to step 202.

[0150] In step 202, the orchestrator starts to perform fault recovery work and checks the replication status of the slave databases. If more than half of the slave databases are replicated abnormally, the orchestrator cannot perform recovery work, does not perform recovery, and ends the fault repair; if more than half of the slave databases are replicated normally, the orchestrator performs recovery work normally and proceeds to step 203.

[0151] In step 203, the relay log application is waited for to be completed. If the relay log application cannot be completed, the orchestrator cannot perform recovery work, and recovery is not performed, and the fault repair is ended; if the relay log application is completed normally, the process proceeds to step 204.

[0152] In step 204, sorting is performed on all slave databases in the database system.

[0153] In step 2041, by executing the "show slave status\G" command, check whether the database replication filter parameters "Replicate_Do_DB / Replicate_Ignore_DB / Replicate_Do_Table / Replicate_Ignore_Table / Replicate_Wild_Do_Table / Replicate_Wild_Ignore_Table / Replicate_Rewrite_DB" exist in the slave database replication status. If any of these items exist in the slave database, exclude it, and select the slave database that does not have any of these items as the candidate master database, and go to step 2042.

[0154] In step 2042, by checking whether the operating status of all slave databases in the database system topology is in a downtime state (the node status is manually set due to hardware maintenance, etc.), the slave databases in the downtime state are eliminated, and the slave databases in a normal state are selected as candidate master databases, and the process proceeds to step 2043.

[0155] In step 2043, the binlog position of the master database that has been executed is no longer selected to identify the latest slave database. Instead, the SQL thread is waited for to finish replaying the relay log. The slave database sorting priority first selects the slave database with the latest binlog synchronization position as the candidate master database, and then proceeds to step 2044.

[0156] In step 2044 , there are multiple MySQL versions in the slave database of the system, and a higher version is better than a lower version. The slave database with a higher version is selected as the candidate master database, and the process goes to step 2045 .

[0157] In step 2045, the orchestrator considers the binlog format (checks the binlog_format parameter) when making the first selection of a new master database based on the sorted slave databases, and preferentially selects the slave database in row format as the candidate master database, and proceeds to step 2046.

[0158] In step 2046, the orchestrator considers the "sync_binlog and innodb_flush_log_at_trx_commit" parameter configurations when making the first new master database selection based on the sorted slave databases, and preferentially selects the slave databases with both parameters configured as "1" as candidate master databases, and proceeds to step 2047.

[0159] In step 2047 , if there are other screening conditions, the selection continues, and after the selection is completed, the process proceeds to step 205 . If there are no other screening conditions, the process proceeds to step 205 .

[0160] In step 205 , a candidate master database is selected as a target candidate master database through step 204 , completing the first master selection, and then proceeding to step 206 .

[0161] In step 206 , the master-slave synchronous replication relationship between the other slave databases and the target candidate master database is rebuilt, and the process proceeds to step 207 .

[0162] In step 207, it is determined whether the target candidate primary database is the ideal primary database based on the configuration options pre-defined by the user. If the target candidate primary database is not the ideal primary database, the ideal primary database is reselected (for example, a candidate primary database in the same data center (IDC) as the primary database is preferentially selected. If not, a candidate primary database in another IDC in the same city is preferentially selected), and the ideal primary database is replaced with the currently selected target candidate primary database, and the process proceeds to step 208. If the target candidate primary database is the ideal primary database, the process proceeds directly to step 208.

[0163] In step 208 , the result of the second master selection is determined according to the selection result of step 207 , and the process proceeds to step 209 .

[0164] In step 209, after the new primary database is finally determined, the new primary database will clean up the replication relationship, set the read-write status, set the original primary node to read-only status, etc., and then complete the failover and provide online database services.

[0165] It should be noted that in the extreme scenario where all slave databases are delayed, no interruption processing is performed, and the entire recovery process is completed after the relaylog is applied. Then a new master database is elected.

[0166] In addition, when the orchestrator actively initiates an online switching action, it is necessary to check whether the database system topology replication status or replication error is normal. If the replication status of all slave databases is abnormal, the switch will not be performed, the existing database system architecture will be retained, the subsequent fault recovery process will not be performed, the database system topology structure will not be changed, and the current database system topology status will be retained to facilitate manual repair.

[0167] The following is a description of an exemplary structure of a database processing device 555 provided in an embodiment of the present application implemented as a software module. In some embodiments, Figure 2 As shown, the software modules stored in the processing device 555 of the database of the memory 550 may include:

[0168] The selection module 5551 is used to select candidate primary databases from M slave databases of the database system based on N screening conditions to obtain T candidate primary databases if a primary database in the database system fails; wherein both N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1.

[0169] The replacement module 5552 is used to replace the master database with a target candidate master database among the T candidate master databases.

[0170] In some embodiments, the apparatus further comprises:

[0171] The determination module is used to determine the probability of each of the candidate primary databases being selected as the target candidate primary database under the N screening conditions; and determine the target candidate primary database from the T candidate primary databases according to the probability.

[0172] In some embodiments, the determination module is further used to determine the probability of the candidate primary database being selected as the target candidate primary database under the N screening conditions according to the weight corresponding to each of the screening conditions and the score of the candidate primary database under each of the screening conditions.

[0173] In some embodiments, the selection module 5551 is further used to select, according to the first screening condition, the slave database that does not have the replication filtering parameter from the M slave databases as a candidate master database.

[0174] In some embodiments, the selection module 5551 is further used to select the slave database in normal operation from the M slave databases as a candidate master database according to the second screening condition.

[0175] In some embodiments, the selection module 5551 is also used to respond to the end of the thread playback relay log, and select the slave database whose synchronization point is higher than the synchronization point threshold from the M slave databases as a candidate master database according to the third filtering condition.

[0176] In some embodiments, the selection module 5551 is also used to select candidate master databases from the M slave databases of the database system based on N screening conditions to obtain T candidate master databases if the number of slave databases in normal replication status among the M slave databases reaches the target number.

[0177] The embodiment of the present application provides a computer program product, which includes a computer program or a computer executable instruction, and the computer program or the computer executable instruction is stored in a computer-readable storage medium. The processor of the electronic device reads the computer executable instruction from the computer-readable storage medium, and the processor executes the computer executable instruction, so that the electronic device executes the database processing method described in the embodiment of the present application.

[0178] The present application embodiment provides a computer-readable storage medium, in which computer executable instructions or computer programs are stored. When the computer executable instructions or computer programs are executed by a processor, the processor will execute the database processing method provided by the present application embodiment, for example, Figure 3 The processing method of the database is shown.

[0179] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.

[0180] In some embodiments, computer executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0181] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0182] As an example, computer executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed at multiple sites and interconnected by a communication network.

[0183] In summary, the new master database selection logic is optimized through the embodiment of the present application. The new master selection logic pursues the principles of latest data priority and data integrity, avoids the risk of data loss to the business system to the greatest extent, and prioritizes the configuration of important database parameters to minimize data loss and improve the consistency of master-slave data. When all slave databases are delayed, it is possible to wait for all slave database relay logs to be fully applied, and then determine the candidate new master database by comparing and reading the master database binlog synchronization site, and then complete the construction of the new system topology. It can improve the accuracy of slave database selection in the event of a master database failure, thereby improving the probability of successful automatic switching of the database system and ensuring the continuity of the business system, optimizing the online switching logic, strengthening the system replication status check, and when a synchronization anomaly is found, the system topology structure is not changed, and the current system topology status is retained for easy manual repair.

[0184] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A method for processing a database, characterized in that: The method comprises: If a master database in the database system fails, based on N screening conditions, candidate master databases are selected from M slave databases in the database system to obtain T candidate master databases; wherein both N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1; The target candidate primary database among the T candidate primary databases replaces the primary database.

2. The method according to claim 1, characterized in that: The method further comprises: Determine the probability of each of the candidate primary databases being selected as a target candidate primary database under the N screening conditions; The target candidate master database is determined from the T candidate master databases according to the probability.

3. The method according to claim 2, characterized in that For each of the candidate primary databases, determining the probability that the candidate primary database is selected as the target candidate primary database under the N screening conditions includes: The probability of the candidate primary database being selected as the target candidate primary database under the N screening conditions is determined according to the weight corresponding to each screening condition and the score of the candidate primary database under each screening condition.

4. The method according to claim 1, characterized in that: The N screening conditions include a first screening condition, where the first screening condition is used to indicate screening of slave databases that do not have a replication filtering parameter; The selecting a candidate master database from the M slave databases of the database system based on the N screening conditions includes: According to the first screening condition, the slave database without the replication filtering parameter is selected from the M slave databases as a candidate master database.

5. The method according to claim 1, characterized in that: The N screening conditions include a second screening condition, where the second screening condition is used to indicate screening of slave databases that are in a normal operating state; The selecting a candidate master database from the M slave databases of the database system based on the N screening conditions includes: According to the second screening condition, the slave database in normal operation is selected from the M slave databases as a candidate master database.

6. The method according to claim 1, characterized in that The N screening conditions include a third screening condition, and the third screening condition is used to indicate screening of slave databases whose synchronization positions are higher than a synchronization position threshold; The selecting a candidate master database from the M slave databases of the database system based on the N screening conditions includes: In response to the end of the thread replaying the relay log, according to the third screening condition, the slave database whose synchronization point is higher than the synchronization point threshold is selected from the M slave databases as a candidate master database.

7. The method according to claim 1, characterized in that The method of selecting a candidate master database from the M slave databases of the database system based on the N screening conditions to obtain T candidate master databases includes: If the number of slave databases in normal replication status among the M slave databases reaches the target number, candidate master databases are selected from the M slave databases of the database system based on N screening conditions to obtain T candidate master databases.

8. A database processing device, characterized in that: The device comprises: A selection module, configured to select a candidate primary database from M slave databases of the database system based on N screening conditions to obtain T candidate primary databases if a primary database in the database system fails; wherein both N and M are integers greater than or equal to 2, and T is an integer greater than or equal to 1; A replacement module is used to replace the master database with a target candidate master database among the T candidate master databases.

9. An electronic device, characterized in that: The electronic device comprises: A memory for storing computer executable instructions; A processor, configured to implement the database processing method according to any one of claims 1 to 7 when executing the computer executable instructions stored in the memory.

10. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the database processing method according to any one of claims 1 to 7 is implemented.

11. A computer program product comprising computer executable instructions or a computer program, characterized in that: When the computer executable instructions or computer program are executed by a processor, the database processing method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Traction motor for electric tricycle and detection method thereof

    CN119483128A