A database read-write separation system and method based on a switching mechanism software
By using a database read/write separation system based on a switching mechanism software, and leveraging virtual Internet Protocol addresses to achieve automatic master database switching and load balancing, the system solves the problems of complex configuration and insufficient real-time performance of existing middleware, thereby improving the high availability and performance of the database system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CLOUD TECH CO LTD
- Filing Date
- 2024-12-04
- Publication Date
- 2026-05-01
AI Technical Summary
Existing database middleware suffers from complex configuration and limited real-time performance when implementing load balancing and high availability.
A database read/write separation system based on a switching mechanism software is adopted. By configuring virtual Internet Protocol addresses for the master and slave databases, automatic switching and load balancing of the master database are achieved, and keepalived is used for real-time monitoring and traffic control.
It simplifies database configuration, improves high availability and real-time performance, reduces system downtime, and optimizes performance and stability.
Smart Images

Figure CN119884068B_ABST
Abstract
Description
A database read / write separation system and method based on exchange mechanism software Technical Field
[0001] This invention relates to the field of computer technology, and specifically to a database read / write separation system and method based on exchange mechanism software. Background Technology
[0002] Currently, a common solution in database management and high availability is to use standalone database middleware (such as ProxySQL and MaxScale) to achieve load balancing and high availability management. These middleware programs are typically deployed in front of the database servers, responsible for routing and distributing database traffic, and performing master-slave traffic failover in the event of a master database failure. While these middleware programs are very useful for providing load balancing and high availability, they also have some limitations. First, they usually require separate deployment and configuration, increasing system complexity. Second, they may require additional hardware resources because they run as a separate software layer. Furthermore, their real-time performance may be limited, requiring a certain amount of time to detect master database failures and perform traffic failover. Summary of the Invention
[0003] In view of this, the present invention provides a database read-write separation system and method based on exchange mechanism software to solve the problems of cumbersome database middleware configuration and limited real-time performance.
[0004] In a first aspect, the present invention provides a database read-write separation system based on a switching mechanism software. The system includes: a database client, a master database, at least one slave database, and a controller, wherein...
[0005] The database client is used to receive traffic requests and allocate traffic to the master and slave databases according to the traffic requests.
[0006] The master database is configured with switching mechanism software and virtual Internet Protocol (VPN) addresses. The switching mechanism software is used to configure the VPN addresses of the master database as read-write VPN addresses and to synchronize the load information between the master database and each slave database.
[0007] The slave database is configured with switching mechanism software and a corresponding virtual Internet Protocol (VPN) address. The switching mechanism software is used to configure the VPN address of the slave database as a read-only VPN address and to synchronize the load information of the corresponding slave database with the master database and other slave databases.
[0008] The controller is used to switch master databases and perform read-only virtual Internet Protocol (VPN) address migration based on the load information of the master database and each slave database.
[0009] The database read / write separation system based on the switching mechanism software provided by this invention simplifies database configuration by setting up a master database with read and write permissions and a slave database with read-only permissions, and by using the type of virtual Internet Protocol address to achieve automatic switching of the master database. It also has strong real-time performance, improves the high availability of the database system, and reduces system downtime.
[0010] Secondly, the present invention provides a database read / write separation method based on exchange mechanism software, the method being applied to the database read / write separation system based on exchange mechanism software in the first aspect, the method comprising:
[0011] Obtain the current operating status of the master database and the current load information of each slave database, and determine whether the master database is experiencing a failure based on its current operating status.
[0012] If the current master database fails, the read / write virtual internet address of the current master database will be turned off, and one of the slave databases will be selected as the new master database based on the load information of each slave database. The virtual internet protocol address of the new master database will be configured as the read / write virtual internet protocol address.
[0013] The database read / write separation method based on switching mechanism software provided by this invention utilizes the configuration of virtual Internet Protocol addresses to achieve master database switching. Through real-time master-slave traffic switching and automated fault handling, it improves the high availability of the database system, reduces system downtime, and enhances system stability and maintainability.
[0014] In one alternative implementation, the method further includes:
[0015] The software-based exchange mechanism between slave databases synchronizes the load information of each slave database.
[0016] If the load of the first slave database is greater than the upper limit of the preset load range, and the load of the second slave database is less than the lower limit of the preset load range, then the read-only virtual Internet Protocol address of the first slave database will be migrated to the second slave database.
[0017] The database read / write separation method based on the switching mechanism software provided by this invention optimizes the performance of the database system by synchronizing load information between each slave database and achieving load balancing through the drifting of virtual Internet Protocol addresses, ensuring that query requests are routed to available nodes and improving data processing efficiency.
[0018] In one optional implementation, after configuring the virtual Internet Protocol address of the new master database to read and write virtual Internet Protocol addresses, the method includes:
[0019] Gradually increase the read and write traffic of the new master database.
[0020] In one optional implementation, after configuring the virtual Internet Protocol address of the new master database to read and write virtual Internet Protocol addresses, the method further includes:
[0021] The original read-only traffic of the new master database will be gradually migrated to other slave databases with read-only virtual Internet Protocol addresses.
[0022] The database read / write separation method based on the switching mechanism software provided by this invention gradually increases the read / write traffic of the new master database after master database switching, and migrates the original read-only traffic to other slave databases, thereby ensuring the data processing efficiency of the master database, improving the high availability of the database system, and reducing system downtime.
[0023] In one optional implementation, selecting one of the slave databases as the new master database based on the current load information of each slave database includes:
[0024] Obtain the current running status of each slave database, and combine it with the current load information of each slave database. Use the preset status scoring rules to score each slave database and obtain the status score of each slave database.
[0025] Compare the status scores of each slave database and select the slave database with the highest status score as the new master database.
[0026] The database read / write separation method based on the switching mechanism software provided by this invention selects the slave database with the highest current status score as the new master database, which can ensure the normal operation of master database read / write traffic, improve data processing efficiency, reduce the need for manual intervention through automatic master / slave switching and virtual Internet Protocol address drift, and improve the stability and maintainability of the system.
[0027] Thirdly, the present invention provides a database read / write separation device based on exchange mechanism software, the device comprising:
[0028] The operation monitoring module is used to obtain the current operating status of the master database and the current load information of each slave database, and to determine whether the master database has failed based on its current operating status.
[0029] The master database switching module is used to shut down the read / write virtual internet address of the current master database if the current master database fails, and select one of the slave databases as the new master database based on the load information of each slave database, and configure the virtual internet protocol address of the new master database to be the read / write virtual internet protocol address.
[0030] Fourthly, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the method described in the first aspect or any corresponding embodiment thereof.
[0031] Fifthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to perform the method described in the first aspect or any corresponding embodiment thereof.
[0032] In a sixth aspect, the present invention provides a computer program product, including computer instructions for causing a computer to perform the method described in the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0033] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0034] Figure 1 is a schematic diagram of the structure of a database read / write separation system based on a switching mechanism software according to an embodiment of the present invention;
[0035] Figure 2 is a flowchart illustrating a database read / write separation method based on a switching mechanism software according to an embodiment of the present invention.
[0036] Figure 3 is a schematic diagram of the main database failure in the database read / write separation method based on the exchange mechanism software according to an embodiment of the present invention;
[0037] Figure 4 is a schematic diagram of switching to a new primary database after the primary database fails in the database read / write separation method based on the switching mechanism software according to an embodiment of the present invention.
[0038] Figure 5 is a schematic diagram of read-only VIP drift in the database read-write separation method based on exchange mechanism software according to an embodiment of the present invention;
[0039] Figure 6 is a structural block diagram of a database read / write separation device based on a switching mechanism software according to an embodiment of the present invention;
[0040] Figure 7 is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0042] This invention provides a database read / write separation system and method based on a switching mechanism software. By configuring virtual Internet Protocol addresses, it achieves switching between primary and backup traffic and address drifting, thereby simplifying database configuration and improving the real-time performance and high availability of database processing.
[0043] According to an embodiment of the present invention, a database read-write separation system based on exchange mechanism software is provided, as shown in Figure 1. The system includes: a database client, a master database, at least one slave database, and a controller.
[0044] As shown in Figure 1, the database client is used to receive traffic requests and allocate traffic to the master and slave databases according to the traffic requests.
[0045] Specifically, a database client can be a software tool or application, primarily used to communicate with the database server to perform functions such as data querying, updating, and management. The database client serves as a medium for users to access the database; its specific functions are mature existing technologies and will not be elaborated upon here.
[0046] As shown in Figure 1, the master database is configured with a switching mechanism software and a virtual Internet Protocol (VIP) address. The switching mechanism software is used to configure the master database's VIP address as a read / write VIP address and to synchronize the load information between the master database and each slave database.
[0047] Specifically, the master database is used to handle read and write traffic. It is configured using the corresponding switching mechanism software (keepalived) and Virtual Internet Protocol address (VIP) to configure one or more servers as a master database. In this embodiment, the switching mechanism software is used to configure the VIP as a read and write VIP address to enable read and write permissions for the master database. At the same time, by modifying the keepalived source code, the current operating status of the master database can be monitored in real time. By continuously monitoring the health status of the master database, the need for master database failure or switchover can be detected in a timely manner.
[0048] Keepalived is a commonly used high availability solution, but this embodiment extends it into a more comprehensive database read / write splitting and load balancing engine. This deep integration is unprecedented, allowing users to achieve high availability and load balancing simultaneously on a single platform without additional middleware or complex configurations. Furthermore, real-time monitoring of the current master database's operational status enables the system to react quickly to master database failures without waiting for periodic checks or manual intervention; this real-time capability is crucial for high availability.
[0049] As shown in Figure 1, the slave database is configured with switching mechanism software and a corresponding virtual Internet Protocol (VPN) address. The switching mechanism software is used to configure the VPN address of the slave database as a read-only VPN address and to synchronize the load information of the corresponding slave database with the master database and other slave databases.
[0050] Specifically, keepalived synchronizes the load information of the read-only VIP connections of each slave database and automatically migrates VIPs to slave machines with lower loads to achieve load balancing. Keepalived manages two types of VIPs: read-write VIPs for read-write operations and read-only VIPs for read operations only, and then uses VIPs for flow control and load balancing.
[0051] As shown in Figure 1, the controller is used to switch master databases and perform read-only virtual Internet Protocol address (VIP) migration based on the load information of the master database and each slave database.
[0052] Specifically, the controller can be an independent controller connected to each keepalived instance, or multiple keepalived instances can be used as controllers. By modifying the keepalived source code, the connection status of each VIP can be checked, and the status of the master database and each slave database, the connection status of VIPs and load information can be synchronized to achieve master-slave traffic switching and load balancing.
[0053] The database read / write system based on keepalived has been deployed. Read and write traffic accesses the master database according to the read / write VIP, while read-only traffic accesses the read-only nodes (slave database). Keepalived controls the drift of read-only VIPs according to the node traffic load, thereby achieving load balancing of read-only traffic.
[0054] The database read / write separation system based on the switching mechanism software provided in this embodiment simplifies database configuration by setting up a master database with read / write permissions and a slave database with read-only permissions, and by using the type of virtual Internet Protocol address to achieve automatic switching of the master database. It also has strong real-time performance, improves the high availability of the database system, and reduces system downtime.
[0055] According to an embodiment of the present invention, a database read / write separation method based on exchange mechanism software is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0056] This embodiment provides a database read / write separation method based on a switching mechanism software, which can be used in the computer system described above or the database read / write separation system based on a switching mechanism software in the previous embodiment. Figure 2 is a flowchart of the database read / write separation method based on a switching mechanism software according to an embodiment of the present invention. As shown in Figure 2, the process includes the following steps:
[0057] Step S101: Obtain the current operating status of the master database and the current load information of each slave database, and determine whether the master database has failed based on the current operating status of the master database.
[0058] Specifically, by modifying the keepalived source code, keepalived can support real-time detection of the current master database's running status, check the connection status of multiple VIPs, and allow different keepalived services to synchronize connection load status in order to coordinate VIP migration.
[0059] The rules for determining whether a fault has occurred based on the current operating status of the master database can be based on existing mature rules, which will not be elaborated here.
[0060] In one specific embodiment, a database consists of two machines, one a master database and the other a slave database, both running the keepalived service. The master database allows read and write operations, while the slave database only allows read operations. When keepalived detects that its machine is the master database, it enables a read-write VIP, routing all write operations to the master database through the read-write VIP. If the master database fails and goes down, keepalived disables the read-write VIP and automatically disconnects the connections associated with it, ensuring that no write operations are sent to the unavailable master database.
[0061] Step S102: If the current master database fails, the read / write virtual internet address of the current master database is turned off, and one of the slave databases is selected as the new master database according to the load information of each slave database. The virtual internet protocol address of the new master database is configured as the read / write virtual internet protocol address.
[0062] Specifically, as shown in Figure 3, if the current master database fails, the read and write traffic segment of the current master database will be disconnected, the read and write VIP of the current master database will be closed, and the connection associated with the read and write VIP will be disconnected.
[0063] As shown in Figure 4, after the current master database fails, a new master database needs to be selected from among the multiple slave databases. The new master database's VIP is configured as a read-write VIP, the read-write VIP is enabled, and the read-only VIP of the new master database is migrated to other slave database machines. After the master database switchover is completed, the read-write VIP of the new master database is enabled, and read and write traffic gradually increases, while the original read-only traffic is gradually migrated to other slave databases with read-only VIPs enabled.
[0064] The database read / write separation method based on switching mechanism software provided in this embodiment utilizes the configuration of virtual Internet Protocol addresses to achieve master database switching. Through real-time master-slave traffic switching and automated fault handling, it improves the high availability of the database system, reduces system downtime, and enhances system stability and maintainability.
[0065] In some alternative implementations, the method further includes:
[0066] The software exchange mechanism between the slave databases synchronizes the load information of each slave database.
[0067] If the load of the first slave database is greater than the upper limit of the preset load range, and the load of the second slave database is less than the lower limit of the preset load range, then the read-only virtual Internet Protocol address of the first slave database will be migrated to the second slave database.
[0068] Specifically, in the case of one master and multiple slaves, the load information of each slave is synchronized through keepalived, as shown in Figure 5. If the load of the first slave is greater than the upper limit of the preset load range and the load of the second slave is less than the lower limit of the preset load range, it means that the load of the first slave is high and the load of the second slave is low. Therefore, the load can be balanced by automatically migrating the VIP to the second slave with the lower load.
[0069] The database read / write separation method based on the switching mechanism software provided in this embodiment optimizes the performance of the database system by synchronizing load information between each slave database and achieving load balancing through the drifting of virtual Internet Protocol addresses. This ensures that query requests are routed to available nodes and improves data processing efficiency.
[0070] In some alternative implementations, after configuring the virtual Internet Protocol address of the new master database to read and write virtual Internet Protocol addresses, the method includes:
[0071] Gradually increase the read and write traffic of the new master database.
[0072] The original read-only traffic of the new master database will be gradually migrated to other slave databases with read-only virtual Internet Protocol addresses.
[0073] Specifically, after configuring the new master database's VIP as a read-write VIP, the new master database primarily handles read and write traffic as a master database. Therefore, the read and write traffic on the new master database is gradually increased, while the read-only traffic previously connected to the new master database is gradually transferred to other slave database machines with read-only VIPs. Once all the read-only traffic previously connected to the new master database has been migrated, the new master database and other slave databases will resume normal operation.
[0074] The database read / write separation method based on a switching mechanism software provided in this embodiment gradually increases the read / write traffic to the new master database after a master database switchover, migrating the original read-only traffic to other slave databases. This ensures the data processing efficiency of the master database, improves the high availability of the database system, and reduces system downtime. By combining database read / write separation with high availability, and through modifications to the Keepalived source code and VIP management, automated traffic control and failover are achieved.
[0075] In some optional implementations, one of the slave databases is selected as the new master database based on the current load information of each slave database, including:
[0076] Obtain the current running status of each slave database, and combine it with the current load information of each slave database. Use the preset status scoring rules to score each slave database and obtain the status score of each slave database.
[0077] Compare the status scores of each slave database and select the slave database with the highest status score as the new master database.
[0078] Specifically, before switching between primary and backup databases, a new primary database needs to be selected from the current slave databases. If only one slave database exists, it is directly selected as the new primary database. If at least two slave databases exist, the operating status and load information of each slave database need to be scored using preset status scoring rules. Based on the scoring results, the slave database to be switched to as the new primary database is determined. The better the performance of each evaluation indicator, the higher the indicator score. The status score of each slave database can be obtained by directly adding the scores of multiple indicators, or by weighting the scores of each indicator according to preset weights. The higher the status score, the more suitable the slave database is as the new primary database. The scoring indicators involved in the preset status scoring rules include:
[0079] (1) Prioritize slave databases with low synchronization latency that are fully synchronized with the master database. Ensure that the selected slave database has fully synchronized with the master database's data. Choosing the slave database with the lowest synchronization latency as the new master database can minimize the risk of data loss. Avoid selecting slave databases with large latency. If a slave database has a large latency, it may not have the latest data. In this case, directly promoting it to the master database may lead to data loss or inconsistency.
[0080] (2) Load and performance: Choose a slave database with a lower load: Generally, a slave database with a lower load can handle write operations better after becoming the master database. You can use monitoring tools (such as SHOW PROCESSLIST, top, iostat, etc.) to evaluate the CPU, memory, disk I / O and network bandwidth usage of each slave database; Choose a slave database with better performance: Slave databases with better hardware configuration (such as faster disks, more memory, etc.) can handle read and write traffic better and are more suitable to serve as the master database.
[0081] (3) Network latency and availability: If the application is distributed in multiple regions, selecting the slave database closest to the application as the new master database can reduce network latency, improve availability, and improve performance.
[0082] (4) Read / Write Splitting Strategy: Consider your current read / write splitting strategy: If you are already using read / write splitting, ensure that the choice of the new master database will not disrupt the existing read / write splitting logic. For example, some slave databases may be dedicated to read-only queries, while others are used for backups or analysis. You need to ensure that the choice of the new master database will not affect these functionalities.
[0083] (5) Ensure that there are no replication failures in the slave database and that the replication thread runs smoothly.
[0084] If a slave database is in poor condition and cannot meet the operational requirements of the original master database, it cannot be used as the new master database even if its load is minimal. This is just an example and not a limitation. The new master database should have less original read-only traffic, minimizing the time required to migrate that traffic to other slave databases. This ensures the continuous availability of the database system in the event of a master database failure, preventing data loss or traffic interruption.
[0085] The database read / write separation method based on the switching mechanism software provided in this embodiment selects the slave database with the highest current status score as the new master database, which can ensure the normal operation of master database read / write traffic, improve data processing efficiency, reduce the need for manual intervention through automatic master / slave switching and virtual Internet Protocol address drift, and improve the stability and maintainability of the system.
[0086] This embodiment is applicable to database management, high availability, and load balancing, and is particularly suitable for application scenarios that require ensuring the availability and performance of database systems, such as online transaction systems, large-scale data analytics, and cloud computing platforms. Online transaction systems: This embodiment can support online transaction systems, ensuring the continuous availability of the database system under high load and failure conditions to prevent transaction interruptions or data loss. Large-scale data analytics: For applications requiring large-scale data analysis, load balancing ensures that queries are distributed to available database nodes, improving data processing efficiency. Cloud computing platforms typically require highly available database systems; this embodiment can be integrated with cloud computing platforms to provide highly available database services.
[0087] This embodiment also provides a database read / write separation device based on a switching mechanism software. This device is used to implement the above embodiments and preferred embodiments, and details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0088] This embodiment provides a database read / write separation device based on a switching mechanism software, as shown in Figure 6, including:
[0089] The operation monitoring module 601 is used to obtain the current operating status of the master database and the current load information of each slave database, and to determine whether the current master database has failed based on the current operating status of the master database.
[0090] The master database switching module 602 is used to shut down the read / write virtual internet address of the current master database if the current master database fails, and select one of the slave databases as the new master database based on the load information of each slave database, and configure the virtual internet protocol address of the new master database to be the read / write virtual internet protocol address.
[0091] In some alternative implementations, the master database switching module 602 includes:
[0092] The load sorting unit is used to sort the load information of each slave database according to the load size to obtain the load sorting result.
[0093] The new master database determination unit is used to select the current slave database with the lowest load from the load sorting results as the new master database.
[0094] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0095] In this embodiment, the database read / write separation device based on the switching mechanism software is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0096] This invention also provides a computer device having a database read / write separation device based on exchange mechanism software as shown in FIG6.
[0097] Please refer to Figure 7, which is a schematic diagram of a computer device according to an optional embodiment of the present invention. As shown in Figure 7, the computer device includes one or more processors 10, a memory 20, and interfaces for connecting the various components, including high-speed interfaces and low-speed interfaces. The various components communicate with each other using different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some optional embodiments, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 7 uses one processor 10 as an example.
[0098] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GPA), or any combination thereof.
[0099] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0100] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0101] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0102] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0103] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0104] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0105] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A database read / write separation system based on a switching mechanism software, characterized in that, The system includes: a database client, a master database, at least one slave database, and a controller. The database client receives traffic requests and allocates traffic to the master and slave databases based on these requests. The master database is configured with switching mechanism software and a virtual Internet Protocol (VIP) address. The switching mechanism software configures the master database's VIP address as a read-write VIP address and synchronizes the load information between the master database and each slave database. Each slave database is configured with switching mechanism software and a corresponding VIP address. The switching mechanism software configures the slave database's VIP address as a read-only VIP address and synchronizes the load information between the corresponding slave database, the master database, and other slave databases. The controller performs master database switching and read-only VIP address migration based on the load information of the master database and each slave database. Specifically, if the load of a first slave database exceeds a preset upper limit and the load of a second slave database is less than a preset lower limit, the read-only VIP address of the first slave database is migrated to the second slave database.
2. A database read / write separation method based on exchange mechanism software, characterized in that, The method is applied to the database read / write separation system based on the switching mechanism software as described in claim 1. The method includes: obtaining the current operating status of the master database and the current load information of each slave database, and determining whether the current master database has failed based on the current operating status of the master database; if the current master database has failed, disabling the read / write virtual Internet address of the current master database, selecting one of the slave databases as the new master database based on the current load information of each slave database, and configuring the virtual Internet Protocol address of the new master database as the read / write virtual Internet Protocol address; synchronizing the load information of each slave database through the switching mechanism software; if the load of the first slave database is greater than the upper limit of a preset load range and the load of the second slave database is less than the lower limit of a preset load range, then migrating the read-only virtual Internet Protocol address of the first slave database to the second slave database.
3. The method according to claim 2, characterized in that, After configuring the virtual Internet Protocol address of the new master database as a read / write virtual Internet Protocol address, the method includes: gradually increasing the read / write traffic of the new master database.
4. The method according to claim 3, characterized in that, After configuring the virtual Internet Protocol address of the new master database as a read-write virtual Internet Protocol address, the method further includes: gradually migrating the original read-only traffic of the new master database to other slave databases with read-only virtual Internet Protocol addresses.
5. The method according to claim 2, characterized in that, The step of selecting one of the slave databases as the new master database based on the current load information of each slave database includes: obtaining the current operating status of each slave database, and combining the current load information of each slave database with a preset status scoring rule to score each slave database to obtain a status score for each slave database; comparing the status scores of each slave database and selecting the current slave database with the highest status score as the new master database.
6. A database read / write separation device based on exchange mechanism software, characterized in that, The device is applied to the database read / write separation system based on the switching mechanism software as described in claim 1. The device includes: a running monitoring module, used to acquire the current running status of the master database and the current load information of each slave database, and determine whether the current master database has failed based on the current running status of the master database; a master database switching module, used to close the read / write virtual internet address of the current master database if the current master database fails, and select one of the slave databases as the new master database based on the current load information of each slave database, and configure the virtual internet protocol address of the new master database as the read / write virtual internet protocol address; a slave database address drifting module, used to synchronize the load information of each slave database through the switching mechanism software; if the load of the first slave database is greater than the upper limit of a preset load range and the load of the second slave database is less than the lower limit of a preset load range, then the read-only virtual internet protocol address of the first slave database is drifted to the second slave database.
7. A computer device, characterized in that, include: A memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, the processor executing the computer instructions to perform the method of any one of claims 2 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the method of any one of claims 2 to 5.
9. A computer program product, characterized in that, Includes computer instructions for causing a computer to perform the method of any one of claims 2 to 5.
Citation Information
Patent Citations
MySQL database cluster processing method and processing system thereof
CN106850759A
High availability method and system based on source redis
CN118034804A