Database read-write separation system and method based on exchange mechanism software
By introducing a read and write separation system based on switching mechanism software in the database, and using virtual Internet protocol addresses to achieve automatic switching and load balancing of the main library, the problems of cumbersome configuration of existing database middleware and limited real-time performance are solved, and the high availability and performance of the database are improved.
Patent Information
- Application Number
- CN202411774458.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-04
AI Technical Summary
The configuration of existing database middleware is cumbersome and has limited real-time performance, making it difficult to effectively achieve high availability and load balancing of the database.
A database read and write separation system based on switching mechanism software is adopted to realize automatic switching and load balancing of the main library by configuring virtual Internet protocol addresses, simplifying database configuration and improving real-time.
It realizes simplification of database configuration, improves the high availability and real-time system, reduces system downtime, and optimizes database performance.
Smart Images

Figure CN119884068A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a database read-write separation system and method based on exchange mechanism software. Background Art
[0002] Currently, in the field of database management and high availability, there is a common solution, which is to use independent database middleware (such as ProxySQL and MaxScale) to achieve load balancing and high availability management. These database middleware are usually deployed in front of the database server and are responsible for routing and distributing database traffic, as well as performing primary-backup traffic switching when the primary database fails. Although these middleware are very useful in providing load balancing and high availability, they also have some limitations. First, they usually need to be deployed and configured separately, which increases the complexity of the system. Second, they may require additional hardware resources because they run as an independent software layer. In addition, their real-time performance may be limited, and it takes a certain amount of time to detect primary database failures and perform traffic switching. 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 complicated 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 exchange mechanism software, the system comprising: a database client, a master library, at least one slave library, and a controller, wherein:
[0005] The database client is used to receive traffic requests and allocate traffic to the master database and the slave database according to the traffic requests;
[0006] The master library is configured with a switching mechanism software and a virtual Internet Protocol address, wherein the switching mechanism software is used to configure the virtual Internet Protocol address of the master library as a read-write virtual Internet Protocol address and synchronize the load information of the master library with each slave library;
[0007] The slave library is configured with a switching mechanism software and a corresponding virtual Internet Protocol address, wherein the switching mechanism software is used to configure the virtual Internet Protocol address of the slave library as a read-only virtual Internet Protocol address, and synchronize the load information of the corresponding slave library with the master library and other slave libraries;
[0008] The controller is used to switch the master library and drift the read-only virtual Internet Protocol address according to the load information of the master library and each slave library.
[0009] The database read-write separation system based on the exchange mechanism software provided by the present invention simplifies the configuration of the database by setting a main library with read-write permissions and a slave library with read-only permissions, and uses the type of virtual Internet Protocol address to realize automatic switching of the main library, and has strong real-time performance, thereby improving the high availability of the database system and reducing system downtime.
[0010] In a second aspect, the present invention provides a database read-write separation method based on exchange mechanism software, the method is applied to the database read-write separation system based on exchange mechanism software in the first aspect, the method comprising:
[0011] Obtain the running status of the current master database and the load information of each slave database, and determine whether the current master database is faulty based on the running status of the current master database;
[0012] If the current master library fails, the read-write virtual Internet address of the current master library will be closed, and one of the slave libraries will be selected as the new master library based on the current load information of each slave library, and the virtual Internet Protocol address of the new master library will be configured as a read-write virtual Internet Protocol address.
[0013] The database read-write separation method based on the exchange mechanism software provided by the present invention realizes the main database switching by configuring the virtual Internet Protocol address, improves the high availability of the database system through real-time main-standby traffic switching and automatic fault handling, reduces the system downtime, and improves the stability and maintainability of the system.
[0014] In an optional embodiment, the method further includes:
[0015] The exchange mechanism software between the slave libraries synchronizes the load information of each slave library;
[0016] If the load of the first slave library is greater than the upper limit of the preset load range and the load of the second slave library is less than the lower limit of the preset load range, the read-only virtual Internet Protocol address of the first slave library is drifted to the second slave library.
[0017] The database read-write separation method based on exchange mechanism software provided by the present invention synchronizes load information between slave libraries, realizes load balancing through the drift of virtual Internet Protocol addresses, optimizes the performance of the database system, ensures that query requests are routed to available nodes, and improves data processing efficiency.
[0018] In an optional implementation, after configuring the virtual Internet Protocol address of the new primary library as a read-write virtual Internet Protocol address, the method includes:
[0019] Gradually increase the read and write traffic of the new master database.
[0020] In an optional implementation, after configuring the virtual Internet Protocol address of the new primary library as a read-write virtual Internet Protocol address, the method further includes:
[0021] Gradually migrate the original read-only traffic of the new master to other slaves with read-only virtual Internet Protocol addresses.
[0022] The database read-write separation method based on exchange mechanism software provided by the present invention gradually increases the read-write traffic of the new master library after the master library is switched, and migrates the original read-only traffic to other slave libraries, thereby ensuring the data processing efficiency of the master library, improving the high availability of the database system, and reducing system downtime.
[0023] In an optional implementation manner, selecting one of the slave libraries as the new master library according to the current load information of each slave library includes:
[0024] Obtain the current running status of each slave library, and combine the current load information of each slave library, use the preset status scoring rules to score each slave library, and obtain the current status score of each slave library;
[0025] Compare the status scores of the current slave libraries and select the current slave library with the largest status score as the new master library.
[0026] The database read-write separation method based on the exchange mechanism software provided by the present invention selects the slave library with the highest current status score as the new master library, which can ensure the normal reading and writing traffic of the master library and improve the data processing efficiency. Through automatic master-slave switching and virtual Internet Protocol address drift, the need for manual intervention is reduced, and the stability and maintainability of the system are improved.
[0027] In a third aspect, 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 operation status of the current master library and the load information of each slave library, and determine whether the current master library has a fault according to the operation status of the current master library;
[0029] The master library switching module is used to close the read-write virtual Internet address of the current master library if a failure occurs in the current master library, and select one of the slave libraries as the new master library according to the current load information of each slave library, and configure the virtual Internet Protocol address of the new master library as a read-write virtual Internet Protocol address.
[0030] In a fourth aspect, 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 method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0031] In a fifth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method of the first aspect or any corresponding embodiment thereof.
[0032] In a sixth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0034] Figure 1 is a structural diagram of a database read-write separation system based on exchange mechanism software according to an embodiment of the present invention;
[0035] Figure 2 It is a flowchart of a database read-write separation method based on exchange mechanism software according to an embodiment of the present invention;
[0036] Figure 3 It is a structural schematic diagram of a main database failure in a database read-write separation method based on exchange mechanism software according to an embodiment of the present invention;
[0037] Figure 4 It is a schematic diagram of switching to a new main database after the main database hangs up in the database read-write separation method based on the exchange mechanism software according to an embodiment of the present invention;
[0038] Figure 5 It is a schematic diagram of read-only VIP drift in a 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 exchange mechanism software according to an embodiment of the present invention;
[0040] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0042] The embodiment of the present invention provides a database read-write separation system and method based on exchange mechanism software, which realizes the switching of primary and backup traffic and address drift by configuring virtual Internet Protocol addresses, so as to simplify database configuration and improve the real-time and high availability of database processing.
[0043] According to an embodiment of the present invention, a database read-write separation system embodiment based on exchange mechanism software is provided, such as Figure 1 As shown, the system includes: a database client, a master database, at least one slave database, and a controller.
[0044] like Figure 1 As shown, the database client is used to receive traffic requests and allocate traffic to the master database and the slave database according to the traffic requests.
[0045] Specifically, the database client can be a software tool or application, which is mainly used to communicate with the database server to achieve data query, update, management and other functions. The database client is a medium for users to access the database, and its specific functions are mature existing technologies and will not be repeated here.
[0046] like Figure 1 As shown, the master library is configured with a switching mechanism software and a virtual Internet Protocol address. The switching mechanism software is used to configure the virtual Internet Protocol address of the master library as a read-write virtual Internet Protocol address and synchronize the load information of the master library with each slave library.
[0047] Specifically, the main library is used to process read and write traffic, and is configured through the corresponding switching mechanism software (keepalived) and virtual Internet Protocol address (Virtual IP, VIP), and one server or multiple servers are configured as a main library. In this embodiment, the switching mechanism software is used to configure the virtual Internet Protocol address as a read-write Internet Protocol address to implement the read and write permission configuration of the main library. At the same time, by modifying the source code of keepalived, real-time monitoring of the current operating status of the main library is achieved. By continuously monitoring the health status of the main library, the need for main library failure or switching can be discovered in a timely manner.
[0048] Keepalived itself is a commonly used high availability solution, but this embodiment expands it into a more comprehensive database read-write separation and load balancing engine. This deep integration is unprecedented, and users can achieve high availability and load balancing on a single platform without additional middleware or complex configuration. In addition, real-time detection of the current main database's operating status enables the system to respond quickly when the main database fails, without having to wait for regular checks or manual intervention. This real-time performance is critical to high availability.
[0049] like Figure 1 As shown, the slave library is configured with a switching mechanism software and a corresponding virtual Internet Protocol address. The switching mechanism software is used to configure the virtual Internet Protocol address of the slave library as a read-only virtual Internet Protocol address, and synchronize the load information of the corresponding slave library with the master library and other slave libraries.
[0050] Specifically, keepalived between the slave libraries will synchronize the load information of the read-only VIP connections of the current slave libraries, and automatically drift the VIP to the slave library machine with lower load to achieve load balancing. keepalived manages two types of VIPs: read-write VIP for read and write operations, and read-only VIP for read operations only, and then performs traffic control and load balancing through VIP.
[0051] like Figure 1 As shown, the controller is used to perform master library switching and read-only virtual Internet Protocol address drift according to the load information of the master library and each slave library.
[0052] Specifically, the controller can be an independent controller connected to each keepalived, or multiple keepalived software can be used as controllers. By modifying the keepalived source code, the connection status of each VIP can be checked, the status of the master library and each slave library, the VIP connection status and load information can be synchronized, and the switching of master and backup traffic and load balancing can be realized.
[0053] The read-write system deployment based on the keepalived database is completed. The read-write traffic accesses the master database according to the read-write VIP, and the read-only traffic accesses the read-only node (slave database). Keepalive controls the drift of the read-only VIP according to the node traffic load to achieve read-only traffic load balancing.
[0054] The database read-write separation system based on the exchange mechanism software provided in this embodiment simplifies the configuration of the database by setting a master library with read-write permissions and a slave library with read-only permissions, and uses the type of virtual Internet Protocol address to realize automatic switching of the master library, and has strong real-time performance, thereby improving the high availability of the database system and reducing system downtime.
[0055] According to an embodiment of the present invention, an embodiment of a database read-write separation method based on an exchange mechanism software is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0056] In this embodiment, a database read-write separation method based on exchange mechanism software is provided, which can be used in the above-mentioned computer system or the database read-write separation system based on exchange mechanism software in the previous embodiment. Figure 2 is a flow chart of a database read-write separation method based on an exchange mechanism software according to an embodiment of the present invention, such as Figure 2 As shown, the process includes the following steps:
[0057] Step S101, obtaining the running status of the current master library and the load information of each current slave library, and determining whether the current master library fails according to the running status of the current master library.
[0058] Specifically, by modifying the keepalived source code, keepalived supports real-time detection of the running status of the current main library, checking the connection status of multiple VIPs, and allowing synchronization of connection loads between different keepalived services to coordinate VIP drift.
[0059] The decision rule for determining whether a fault occurs according to the current operating status of the main database can be the existing mature decision rules, which will not be repeated here.
[0060] In a specific embodiment, a database consists of two machines, which deploy a master database and a slave database respectively and run the keepalived service. The master database allows read and write operations, and the slave database only allows read operations. When keepalived detects that the machine is the master database, it will enable the read-write VIP and route all write operations to the master database through the read-write VIP. If the master database fails, keepalived will shut down the read-write VIP and automatically disconnect the connection related to the read-write VIP to ensure that write operations are not sent to the unavailable master database.
[0061] Step S102: If the current master library fails, the read-write virtual Internet address of the current master library is closed, and one of the slave libraries is selected as the new master library according to the current load information of each slave library, and the virtual Internet Protocol address of the new master library is configured as a read-write virtual Internet Protocol address.
[0062] Specifically, Figure 3 As shown, if the current master database fails, the read and write traffic segments of the current master database are disconnected, the read and write VIP of the current master database is closed, and the connections related to the read and write VIP are disconnected.
[0063] like Figure 4 As shown in the figure, after the current master database hangs up, you need to select a slave database from the current multiple slave databases as the new master database, configure the VIP of the new master database as a read-write VIP, enable the read-write VIP, and drift the read-only VIP of the new master database to other slave database machines. After the master database switch is completed, turn on the read-write VIP of the new master database, the read-write traffic gradually increases, and the original read-only traffic gradually migrates to other slave databases with the read-only VIP turned on.
[0064] The database read-write separation method based on the exchange mechanism software provided in this embodiment uses the configuration of the virtual Internet Protocol address to realize the master database switching, and improves the high availability of the database system through real-time master-slave traffic switching and automated fault handling, reduces system downtime, and improves the stability and maintainability of the system.
[0065] In some optional embodiments, the method further comprises:
[0066] The exchange mechanism software between the slave libraries synchronizes the load information of each slave library.
[0067] If the load of the first slave library is greater than the upper limit of the preset load range and the load of the second slave library is less than the lower limit of the preset load range, the read-only virtual Internet Protocol address of the first slave library is drifted to the second slave library.
[0068] Specifically, for the case of one master and multiple slaves, the load information of each slave is synchronized through keepalived, such as Figure 5 As shown, if the load of the first slave library is greater than the upper limit of the preset load range, and the load of the second slave library is less than the lower limit of the preset load range, it means that the current load of the first slave library is higher and the load of the second slave library is lower, so load balancing can be achieved by automatically drifting VIP to the second slave library with lower load.
[0069] The database read-write separation method based on the exchange mechanism software provided in this embodiment synchronizes load information between slave libraries and realizes load balancing through the drift of virtual Internet Protocol addresses, thereby optimizing the performance of the database system, ensuring that query requests are routed to available nodes, and improving data processing efficiency.
[0070] In some optional implementations, after configuring the virtual Internet Protocol address of the new primary library as a read-write virtual Internet Protocol address, the method includes:
[0071] Gradually increase the read and write traffic of the new master database.
[0072] Gradually migrate the original read-only traffic of the new master to other slaves with read-only virtual Internet Protocol addresses.
[0073] Specifically, after configuring the VIP of the new master database as a read-write VIP, the new master database mainly processes read-write traffic as the master database, so the read-write traffic of the new master database is gradually increased, and the read-only traffic previously connected to the new master database is gradually transferred to other slave database machines with read-only VIPs. When all the read-only traffic of the new master database is migrated, the new master database and other slave databases will resume normal operation.
[0074] The database read-write separation method based on the exchange mechanism software provided in this embodiment gradually increases the read-write traffic of the new master database after the master database is switched, 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. Combining database read-write separation with high availability, automated traffic control and fault switching are achieved through Keepalived source code modification and VIP management.
[0075] In some optional implementations, selecting one of the slave libraries as the new master library according to the current load information of each slave library includes:
[0076] Obtain the current running status of each slave library, and combine the current load information of each slave library, use the preset status scoring rules to score each slave library, and obtain the current status score of each slave library;
[0077] Compare the status scores of the current slave libraries and select the current slave library with the largest status score as the new master library.
[0078] Specifically, before switching the master-slave traffic, you need to select one from the current slave libraries as the new master library. If there is only one slave library, the current slave library is directly used as the new master library. If there are at least two slave libraries, the current operating status and load information of each slave library needs to be scored for each current slave library using the preset status scoring rules. The current slave library that is switched to the new master library is determined based on the scoring results. The better the performance of each evaluation indicator, the higher the indicator score. You can directly add up multiple indicator scores to get the status score of each slave library, or you can perform weighted calculations on each indicator score according to preset weights to get the status score of each slave library. The larger the status score, the more suitable the slave library is as the new master library. The scoring indicators involved in the preset status scoring rules include:
[0079] (1) Small synchronization delay. Give priority to slaves that are fully synchronized with the master. Ensure that the selected slave has fully synchronized the data of the master. Select the slave with the smallest synchronization delay as the new master to minimize the risk of data loss. Avoid selecting slaves with large delays. If a slave has a large delay, it may not have the latest data. In this case, directly promoting it to the master may result in data loss or inconsistency.
[0080] (2) Load and performance, choose slaves with lower load: Generally, slaves with lower load can better handle write operations after becoming the master. 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; choose slaves with better performance: slaves with better hardware configuration (such as faster disks, more memory, etc.) can better handle read and write traffic and are more suitable for the role of the master.
[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 separation strategy Consider the current read-write separation strategy: If you are already using read-write separation, make sure that the selection of the new master database does not disrupt the existing read-write separation logic. For example, some slave databases may be dedicated to read-only queries, while other slave databases are used for backup or analysis. You need to ensure that the selection of the new master database does not affect these functions.
[0083] (5) Ensure that there are no replication failures in the slave database and that the replication thread proceeds smoothly.
[0084] If the operating status of a slave is very poor and cannot meet the operating requirements of the original master, then even if the slave has the smallest load, it cannot be used as the new master. This is just an example, but not limited to this. The original read-only traffic of the new master is less, and the time required to migrate the original read-only traffic to other slaves is the least, ensuring the continuous availability of the database system when the master fails to prevent data loss or traffic interruption.
[0085] The database read-write separation method based on the exchange mechanism software provided in this embodiment selects the slave library with the highest current status score as the new master library, which can ensure the normal reading and writing traffic of the master library and improve the data processing efficiency. Through automatic master-slave switching and virtual Internet Protocol address drift, the need for manual intervention is reduced, and the stability and maintainability of the system are improved.
[0086] This embodiment is applicable to the fields of database management, high availability and load balancing, and is particularly applicable to application scenarios that require ensuring the availability and performance of the database system, such as online trading systems, large-scale data analysis, and cloud computing platforms. Online trading systems: can be used to support online trading systems to ensure the continuous availability of database systems under high load and failure conditions to prevent transaction interruptions or data loss; large-scale data analysis: for applications that require large-scale data analysis, the load balancing function can ensure that queries are distributed to available database nodes to improve data processing efficiency; cloud computing platforms usually require highly available database systems, and this embodiment can be integrated with cloud computing platforms to provide high-availability database services.
[0087] In this embodiment, a database read-write separation device based on exchange mechanism software is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made are not repeated here. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0088] This embodiment provides a database read-write separation device based on exchange mechanism software, such as Figure 6 As shown, including:
[0089] The operation monitoring module 601 is used to obtain the operation status of the current master library and the load information of each slave library, and determine whether the current master library fails according to the operation status of the current master library.
[0090] The master library switching module 602 is used to close the read-write virtual Internet address of the current master library if a fault occurs in the current master library, and select one of the slave libraries as the new master library based on the current load information of each slave library, and configure the virtual Internet Protocol address of the new master library as a read-write virtual Internet Protocol address.
[0091] In some optional implementations, the master library switching module 602 includes:
[0092] The load sorting unit is used to sort the load information of each slave library according to the load size to obtain the load sorting result.
[0093] The new master library determination unit is used to select the current slave library with the smallest load as the new master library from the load sorting result.
[0094] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0095] The database read-write separation device based on the exchange mechanism software in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0096] The embodiment of the present invention also provides a computer device having the above Figure 6 The database read-write separation device based on the exchange mechanism software is shown.
[0097] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0098] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0099] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0100] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0101] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0102] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0103] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0104] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0105] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A database read-write separation system based on exchange mechanism software, characterized in that: The system comprises: a database client, a master database, at least one slave database, and a controller, wherein: A database client is used to receive a traffic request and allocate traffic to a master database and a slave database according to the traffic request; The master library is configured with a switching mechanism software and a virtual Internet Protocol address, wherein the switching mechanism software is used to configure the virtual Internet Protocol address of the master library as a read-write virtual Internet Protocol address and synchronize the load information of the master library with each slave library; The slave library is configured with a switching mechanism software and a corresponding virtual Internet Protocol address, wherein the switching mechanism software is used to configure the virtual Internet Protocol address of the slave library as a read-only virtual Internet Protocol address, and synchronize the load information of the corresponding slave library with the master library and other slave libraries; The controller is used to switch the master library and drift the read-only virtual Internet Protocol address according to the load information of the master library and each slave library.
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 exchange mechanism software according to claim 1, and the method comprises: Obtain the running status of the current master database and the load information of each slave database, and determine whether the current master database is faulty based on the running status of the current master database; If the current master library fails, the read-write virtual Internet address of the current master library will be closed, and one of the slave libraries will be selected as the new master library based on the current load information of each slave library, and the virtual Internet Protocol address of the new master library will be configured as a read-write virtual Internet Protocol address.
3. The method according to claim 2, characterized in that The method further comprises: The exchange mechanism software between the slave libraries synchronizes the load information of each slave library; If the load of the first slave library is greater than the upper limit of the preset load range and the load of the second slave library is less than the lower limit of the preset load range, the read-only virtual Internet Protocol address of the first slave library is drifted to the second slave library.
4. The method according to claim 2, characterized in that: After configuring the virtual Internet Protocol address of the new master library as a read-write virtual Internet Protocol address, the method includes: Gradually increase the read and write traffic of the new master database.
5. The method according to claim 4, characterized in that After configuring the virtual Internet Protocol address of the new master library as a read-write virtual Internet Protocol address, the method further includes: Gradually migrate the original read-only traffic of the new master to other slaves with read-only virtual Internet Protocol addresses.
6. The method according to claim 2, characterized in that The step of selecting one of the slave libraries as the new master library according to the current load information of each slave library includes: Obtain the current running status of each slave library, and combine the current load information of each slave library, use the preset status scoring rules to score each slave library, and obtain the current status score of each slave library; Compare the status scores of the current slave libraries and select the current slave library with the largest status score as the new master library.
7. A database read-write separation device based on exchange mechanism software, characterized in that: The device comprises: The operation monitoring module is used to obtain the operation status of the current master library and the load information of each slave library, and determine whether the current master library has a fault according to the operation status of the current master library; The master library switching module is used to close the read-write virtual Internet address of the current master library if a failure occurs in the current master library, and select one of the slave libraries as the new master library according to the current load information of each slave library, and configure the virtual Internet Protocol address of the new master library as a read-write virtual Internet Protocol address.
8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 2 to 6 by executing the computer instructions.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method according to any one of claims 2 to 6.
10. A computer program product, characterized in that The method comprises computer instructions for causing a computer to execute the method according to any one of claims 2 to 6.
Citation Information
Patent Citations
Method and device capable of achieving database reading and writing separation
CN104504145A
MySQL database cluster processing method and processing system thereof
CN106850759A
Database high availability method, device, system and storage medium
CN111581284A
Database cluster switching method and device, equipment and storage medium
CN112749045A
Mobile terminal monitoring method for mining state of working face cluster
CN112817791A