A database fault processing method, device, equipment and storage medium
By creating a database and copying data on the backup node, the problem of data loss during database failure recovery is solved, and data consistency and high availability between master and slave nodes are achieved.
Patent Information
- Application Number
- CN202210969279.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-12
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-08-12
AI Technical Summary
Existing master-slave replication technology is prone to data loss during database failure recovery and cannot guarantee data consistency between master and slave nodes.
Create a database on the backup node and copy the data from the local node to the backup node to establish a master-slave replication relationship. Switch the failed database only when the latest data is stored on the local node, and automatically restore the master-slave replication relationship.
It enables rapid restoration of data consistency between master and slave nodes without data loss, thus improving the high availability of the database.
Smart Images

Figure CN115269556B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, more particularly, to a database fault processing method, device, equipment and storage medium. BACKGROUND
[0002] MySQL (relational database management system), Oracle (relational database management system), PostgreSQL (relational database management system) and other databases have been widely used in Internet companies. With the consideration of database security and controllability, higher requirements are put forward for database architecture, and how to ensure data consistency is the most concerned problem. The current database master-slave replication technology includes: master-slave asynchronous replication technology, master-slave semi-synchronous replication technology and master-slave full-synchronous replication technology. If the above master-slave replication technology is abnormal, when the database is recovered, data loss phenomenon will exist, and the data consistency between the master and slave nodes cannot be guaranteed. SUMMARY
[0003] The purpose of the present application is to provide a database fault processing method, device, equipment and storage medium, so as to avoid data loss phenomenon when the database is recovered, and ensure the data consistency between the master and slave nodes.
[0004] To achieve the above purpose, the present application provides a database fault processing method, which comprises:
[0005] determining a target node corresponding to the node; wherein the database of the node and the database of the target node have a master-slave replication relationship;
[0006] If it is monitored that the target node fails, and the latest data is stored in the database of the node, a database is created in the backup node, the data in the database of the node is copied to the database of the backup node, and the master-slave replication relationship between the database of the node and the database of the backup node is established.
[0007] Wherein, before creating a database in the backup node, it further comprises:
[0008] canceling the master-slave replication relationship between the database of the node and the database of the target node;
[0009] If the node is a first master node, and the target node is a first slave node, the first master node provides database read-write service;
[0010] If the node is a second slave node, and the target node is a second master node, the second slave node is promoted to a third master node, and the third master node provides database read-write service.
[0011] wherein the creating a database in the backup node comprises:
[0012] selecting a third slave node from the plurality of backup nodes to create a database according to a health state of each backup node.
[0013] wherein after the first master node / third master node provides database read-write services, further comprising:
[0014] detecting whether the first master node / third master node has an un-failed slave node;
[0015] if not, continuing to perform the step of creating a database in the backup node;
[0016] if yes, providing database read-write services through the first master node / third master node and the corresponding un-failed slave node.
[0017] wherein the database of the current node storing the latest data comprises:
[0018] judging whether the current node is in a data consistent state;
[0019] if yes, determining that the database of the current node stores the latest data;
[0020] if not, judging whether the current node is a master node;
[0021] if the current node is a master node, determining that the database of the current node stores the latest data; if the current node is a slave node, determining that the database of the current node does not store the latest data.
[0022] wherein after the establishing the master-slave replication relationship between the database of the current node and the database of the backup node, further comprising:
[0023] storing the location information of the current node and the location information of the backup node to a storage unit.
[0024] wherein the method further comprises:
[0025] if the failure of the target node has been recovered, the target node judges whether there is a master-slave replication relationship between the database of the target node and the database of the current node according to the location information in the storage unit;
[0026] if not, deleting the database of the target node;
[0027] if yes, continuing to provide database read-write services through the current node and the target node.
[0028] To achieve the above object, the application further provides a database fault processing device, comprising:
[0029] A determining module is configured to determine a target node corresponding to the node; wherein the database of the node and the database of the target node have a master-slave replication relationship;
[0030] A creating module is configured to create a database in a backup node when the target node is monitored to have a fault and the latest data is stored in the database of the node;
[0031] A copying module is configured to copy the data in the database of the node to the database of the backup node;
[0032] A setting module is configured to establish a master-slave replication relationship between the database of the node and the database of the backup node.
[0033] To achieve the above object, the application further provides an electronic device, comprising:
[0034] A memory is configured to store a computer program;
[0035] A processor is configured to execute the computer program to realize the steps of the above database fault processing method.
[0036] To achieve the above object, the application further provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to realize the steps of the above database fault processing method.
[0037] According to the above scheme, the embodiment of the application provides a database fault processing method, device, equipment and storage medium; in the scheme, the node needs to monitor whether the target node has a fault, the database of the target node and the database of the node have a master-slave replication relationship; if the target node is monitored to have a fault and the latest data is stored in the database of the node, a database is created in a backup node, the data in the database of the node is copied to the database of the backup node, and a master-slave replication relationship is established between the database of the node and the database of the backup node. Through the method, when the database has a fault, the fault database can be quickly switched, the master-slave replication relationship between the master node and the slave node is automatically recovered, the recovery speed is improved, and the high availability of the database is improved; and the scheme switches the fault database only when the latest data is stored in the database of the node, thereby realizing the high availability of the master-slave database under the premise of not losing data and realizing the data consistency between the master node and the slave node. BRIEF DESCRIPTION OF DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the accompanying drawings in the following description are only some embodiments of the present application, and all other drawings obtained by those of ordinary skill in the art without creative effort based on these drawings belong to the protection scope of the present application.
[0039] Figure 1 A database fault processing system structure diagram disclosed by the embodiment of the present application;
[0040] Figure 2 A database fault processing method flow diagram disclosed by the embodiment of the present application;
[0041] Figure 3 A slave node fault processing flow chart disclosed by the embodiment of the present application;
[0042] Figure 4 A master node fault processing flow chart disclosed by the embodiment of the present application;
[0043] Figure 5 A database fault processing device structure diagram disclosed by the embodiment of the present application;
[0044] Figure 6 An electronic equipment structure diagram disclosed by the embodiment of the present application. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present application will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort belong to the protection scope of the present application.
[0046] In order to facilitate understanding, the system architecture to which the technical solutions of the present application are applicable will be introduced as follows. Figure 1 A database fault processing system structure diagram disclosed by the embodiment of the present application, through Figure 1As can be seen, the system mainly comprises the node 11 and the target node 12. The node 11 is used to execute the database processing scheme, and the node 11 can be a master node or a slave node, which is not specifically limited herein. The target node 12 is a node to be detected for failure in the application, and the target node 12 can be a master node or a slave node. Moreover, the database of the master node in the application has a master-slave replication relationship with the database of the target node 12. If the node 11 is a master node, the target node 12 is a slave node having a master-slave replication relationship with the master node. If the node 11 is a slave node, the target node 12 is a master node having a master-slave replication relationship with the slave node. Moreover, in each node, a database and a service for implementing database failure processing are arranged. In the embodiment, the service for implementing database failure processing is referred to as a database management service, which can be used to monitor whether a slave node having a master-slave replication relationship fails and to implement automatic operation and maintenance processing for a failed node. That is to say, in the application, whether a master node or a slave node, the database failure processing scheme described in the application can be executed. As long as the target node is detected to fail, a database can be created in a backup node to realize quick switching of the database in the failed node, so as to automatically recover the master-slave replication relationship and improve the recovery speed. Moreover, the scheme switches the failed database only when the latest data is stored in the database of the node, thereby realizing high availability of the master-slave database under the premise of no data loss and realizing data consistency between the master node and the slave node.
[0047] Referring to Figure 2 A database failure processing method flow diagram disclosed in the embodiment of the application is shown in FIG. 1. By means of Figure 2 As can be seen, the database processing method comprises the following steps.
[0048] S101, determining a target node corresponding to the node; wherein the database of the node has a master-slave replication relationship with the database of the target node;
[0049] Specifically, each master-slave database cluster includes one master node and a plurality of slave nodes, the master node monitors the working state of each slave node, and each slave node can also monitor the working state of the master node. Moreover, when the master-slave database cluster is in a normal state, each node does not fail, and at this time, a master-slave replication relationship needs to be established between the database of the master node and the database of the slave node. The master-slave replication relationship can be a master-slave asynchronous replication relationship established by using a master-slave asynchronous replication technology for the databases of the master node and the slave node, can be a master-slave semi-synchronous replication relationship established by using a master-slave semi-synchronous replication technology for the databases of the master node and the slave node, or can be a master-slave full-synchronous replication relationship established by using a master-slave full-synchronous replication technology for the databases of the master node and the slave node. However, when the master-slave asynchronous replication technology is used, the master database returns the result to the client immediately after executing the transaction submitted by the client, and does not care about the result received by the slave database, which may cause the slave database to not synchronize the data to the master database when the master database is down due to some reasons, resulting in inconsistent contents of the databases of the master node and the slave node. When the master-slave full-synchronous replication technology is used, it is required that all slave nodes receive the transaction and apply it to the slave database, and then the thread of the master database can complete the commit submission and return to the client, which may prolong the time for completing a transaction and cause a sharp decline in performance. When the master-slave semi-synchronous replication technology is used, the master database does not return to the client immediately after executing the transaction submitted by the client, but waits for at least one slave database to receive and write to the relay log before returning to the client. Therefore, in order to balance the performance and data consistency, the master-slave database cluster preferably uses the master-slave semi-synchronous replication technology, and thus the database of the master node and the database of the target node have a master-slave semi-synchronous replication relationship.
[0050] S102, if it is monitored that the target node fails and the database of the master node stores the latest data, a database is created in the backup node, the data in the database of the master node is copied to the database of the backup node, and a master-slave replication relationship is established between the database of the master node and the database of the backup node.
[0051] In this embodiment, the database management service in the master node needs to monitor whether the target node fails. At this time, the target node fails, which can be that the database in the target node fails, or that the communication between the master node and the target node fails, which is not specifically limited herein. As long as the master node detects that the working state of the target node is abnormal, it is determined that the target node fails.
[0052] It should be noted that when monitoring whether the target node fails, the node can periodically detect whether the target node fails according to a pre-set time interval. For example, if the time interval is 1 minute, the node needs to detect whether the target node fails every 1 minute. If the target node does not fail at this time, the node waits for 1 minute and then detects whether the target node fails again. In this way, the failed node can be detected in time. Of course, the time interval is only taken as an example to illustrate the scheme. In actual application, the time interval can be set according to actual needs.
[0053] In the embodiment, if the node monitors that the target node fails, before switching the fault database, it is first determined which node in the master-slave database cluster has the latest data stored in the database. If the node that does not fail has the latest data stored in the database, when the database is switched, the latest data stored in the node is copied to the database of the backup node. This way does not cause data loss. If the target node that fails has the latest data stored in the database, if the database is continued to be switched, only the non-latest data in the node is copied to the database of the backup node, and the latest data in the target node is lost. Therefore, in the application, only when the database of the node has the latest data stored in it, a database is created in the backup node. Otherwise, no database is created in the backup node, and the target node failure is continued to be repaired. In this way, data loss can be avoided when the database is repaired, high availability of the master-slave database is realized under the premise of no data loss, and data consistency between the master node and the slave node is realized. If the target node has not been repaired after waiting for a predetermined time, a reminder information can be sent to the administrator or the subsequent step of creating a database in the backup node is automatically executed. The specific execution operation can be pre-set, which is not specifically limited here.
[0054] Further, if the database of the node has the latest data stored in it, the node will select a normal node that does not fail to replace the target node. The node that replaces the target node is called a backup node in the scheme. After the backup node is selected, a database can be created in the backup node, the data in the database of the node is copied to the database of the backup node, the master-slave replication relationship between the database of the node and the database of the target node is cancelled, and the master-slave replication relationship between the database of the node and the database of the backup node is established. After the above operations are performed, the node and the backup node can restore the master-slave database cluster and normally provide database read-write services to the outside.
[0055] It should be noted that if the node is a master node, when the slave node is monitored to fail, and the master-slave replication relationship between the database of the node and the database of the target node is cancelled, the master node can normally provide database read and write services to the outside and continue to execute the subsequent steps of selecting a backup node, and restoring the master-slave database cluster through the master node and the backup node; if the node is a slave node, when the master node is monitored to fail, the master-slave replication relationship between the database of the node and the database of the target node can be cancelled, and the subsequent steps of selecting a new master node (backup node) are continued, and after the master-slave database cluster is restored through the new master node and the slave node, the new master node normally provides database read and write services to the outside, but when the database read and write services are provided to the outside in this way, a delay will be caused by the operations of selecting a new master node and copying data, therefore, in order to quickly restore the business access of the database, the slave node can be directly upgraded to a new master node, and after the new master node normally provides database read and write services to the outside, the subsequent steps of selecting a backup node and restoring the master-slave database cluster through the new master node and the backup node are continued.
[0056] As can be seen from the above, when the database node fails, the master-slave database cluster can be quickly restored through the creation of a backup node, and the master-slave replication relationship between the databases is automatically restored, the recovery speed is improved, the quick switching of the failed database is realized, and the high availability of the database is improved. Moreover, before the database is created in the backup node, it can be judged whether the data in the node providing the business service after the automatic switching of the failed database is the latest, and only when the data in the node providing the service after the switching is the latest, the automatic switching can be performed, so that the high availability of the master-slave database under the premise of no data loss is realized, and the data consistency between the master node and the slave node is realized.
[0057] Based on the database failure processing method described in the above embodiment, in the present embodiment, in order to quickly provide services to the outside after the target node fails and to avoid the impact of node failure on business as much as possible, the following operations need to be performed before the database is created in the backup node: cancelling the master-slave replication relationship between the database of the node and the database of the target node; if the node is a first master node and the target node is a first slave node, providing database read and write services through the first master node; if the node is a second slave node, and the target node is a second master node, upgrading the second slave node to a third master node, and providing database read and write services through the third master node.
[0058] Moreover, the process of creating a database in the backup node in the present embodiment specifically includes: selecting a third slave node for creating a database from a plurality of backup nodes according to the health status of each backup node.
[0059] It should be noted that when creating a database on a backup node, this solution requires selecting the node to create the database from multiple backup nodes according to pre-defined node selection rules. Specifically, these rules can be based on the health status of each backup node. This health status can be reflected by different parameters, such as disk status, remaining memory, and CPU (central processing unit) activity level. For example, if the node selection rule is based on the CPU activity level of each backup node, then when creating the database, the CPU activity level of each backup node is first determined, and the backup node with the lowest activity level is selected as the node for database creation.
[0060] Furthermore, as described in the above embodiments, if this node is the first master node and the failed target node is the first slave node, then in order to restore the master-slave replication relationship, the backup node that created the database needs to be made a slave node so that it can restore the master-slave replication relationship with the first master node. If this node is the second slave node and the failed target node is the second master node, then the second slave node needs to be promoted to the third master node. In this case, in order to restore the master-slave replication relationship, the backup node that created the database also needs to be made a slave node so that it can restore the master-slave replication relationship with the third master node. Therefore, in this embodiment, the slave node that created the database will be selected as the third slave node from among multiple backup nodes.
[0061] See Figure 3 This is a flowchart of a slave node failure handling process disclosed in an embodiment of the present invention. If the current node is the first master node, then the target node is the first slave node. If the database management service of the first master node detects a failure in the first slave node, the master-slave replication relationship between the databases of the first master node and the first slave node is cancelled. The database read and write service is provided by the first master node, and a third slave node is selected from the backup nodes. It should be noted that, in order to distinguish the third slave node selected when the slave node fails from the third slave node selected when the master node fails, this embodiment will... Figure 3 The selected third slave node is marked as the third slave node (1), and... Figure 4 The selected third slave node is marked as the third slave node (2). Then, after selecting the third slave node (1), a database is created in the third slave node (1), and the data in the database of the first master node is copied to the database of the third slave node (1), establishing a master-slave replication relationship between the database of the first master node and the database of the third slave node (1). See also Figure 4If the node is the second slave node, the target node is the second master node at this time, if the database management service of the second slave node monitors the failure of the second master node at this time, the master-slave replication relationship between the database of the second master node and the database of the second slave node is cancelled at this time, the second slave node is upgraded to the third master node, the database read-write service is provided through the third master node, the third slave node (2) is selected from the backup node, the database is created in the third slave node (2), the data in the database of the third master node is copied to the database of the third slave node (2), and the master-slave replication relationship between the database of the third master node and the database of the third slave node (2) is established.
[0062] As can be seen from the above, when the database node fails, the master-slave database cluster can be quickly recovered through the creation of the backup node; if the slave node fails, the master node can provide the database read-write service to the outside in time, if the master node fails, the slave node can quickly provide the database read-write service to the outside after being upgraded to the new master node, through the above method, the business access of the database can be quickly recovered, and the high availability of the database is improved.
[0063] As can be seen from the above embodiment, in order to quickly provide the service to the outside after the target node fails, the database read-write service needs to be provided through the first master node / third master node which is not failed, so as to avoid the influence of the node failure on the business as much as possible. In the embodiment, after the database read-write service is provided through the first master node / third master node which is not failed, whether the first master node / third master node has the slave node which is not failed is detected before the database is created in the backup node; if not, the step of creating the database in the backup node is continued; if yes, the database read-write service is provided through the first master node / third master node and the corresponding slave node which is not failed.
[0064] Specifically, in a master-slave database cluster, there can be one master node and one slave node, or one master node and multiple slave nodes. Therefore, in this embodiment, after providing database read-write services through the non-failed master node, it is further detected whether the master node providing external services has a slave node. If there is a slave node, it indicates that the current master-slave database cluster can provide normal services to the outside through the non-failed master-slave node. Even if any node in the master-slave node fails again, it can continue to provide services to the outside through the remaining non-failed node. Therefore, in order to save system resources, the application can not perform the operation of creating a database in the backup node when the master node has a corresponding slave node, and provide database read-write services through the non-failed master node and the corresponding slave node. If the master node does not have a corresponding slave node, although services can be provided to the outside through the master node, if the master node fails at this time, it cannot continue to provide services to the outside. Therefore, in the application, if the master node does not have a corresponding slave node, a third slave node needs to be selected, and a database is created in the third slave node. The data in the database of the master node is copied to the database of the third slave node, and a master-slave replication relationship is established between the database of the master node and the database of the third slave node, to normally provide services to the outside. It should be noted that the non-failed master node in this embodiment can be the non-failed first master node in the above embodiment, or the third master node upgraded from the non-failed second slave node in the above embodiment, which is not specifically limited here.
[0065] As can be seen from the above, in this embodiment, a database is created in a backup node only when the non-failed master node does not have a corresponding slave node. If the non-failed master node has a corresponding slave node, the current master-slave node can continue to provide services to the outside. In this way, resource consumption can be reduced without affecting system performance.
[0066] Based on the database failure processing method described in the above embodiment, in this embodiment, the process of determining whether the database of the node stores the latest data specifically includes: judging whether the node is in a data consistent state; if yes, determining that the database of the node stores the latest data; if no, judging whether the node is a master node; if the node is a master node, determining that the database of the node stores the latest data; if the node is a slave node, determining that the database of the node does not store the latest data.
[0067] Specifically, the embodiment also provides a distributed consistency storage unit, which is used to record node state information of a node in which the latest data is stored in the master-slave database cluster. If the node state information of the node is a data consistent state, it indicates that the data between the corresponding master-slave nodes is completely consistent, and then the node must store the latest data. For example, the master node 1 and the slave node 1 have a master-slave replication relationship, and the master node 1 fails. At this time, it is needed to determine whether the node state information of the slave node 1 is a data consistent state. If the node state information is a data consistent state, it indicates that the slave node 1 stores the latest data. In addition, since the master-slave nodes replicate data in the following manner: the master node successfully writes data and then replicates the data to the slave node, even if the data between the slave node and the master node is not consistent, the master node still stores the latest data. Therefore, when it is determined that the node is not in a data consistent state, the node type is also used to determine whether the node stores the latest data, that is, it is determined whether the node is a master node. If the node is a master node, it is determined that the database of the node stores the latest data. If the node is a slave node, it is determined that the node does not store the latest data.
[0068] As can be seen from the above, in the embodiment, whether the node stores the latest data can be determined according to the node state information and the node type. In this way, data loss can be prevented when the database fails and is automatically switched.
[0069] Based on the database fault processing method described in the above embodiment, in the embodiment, the storage unit also stores the position information of each node in the master-slave database cluster. Therefore, after the master-slave replication relationship between the database of the node and the database of the backup node is established, the position information of the node and the position information of the backup node are stored in the storage unit.
[0070] It should be noted that the storage unit only stores the position information of each master-slave node in the current master-slave database cluster. If the target node is replaced by the backup node after the target node fails, after the position information of the node and the position information of the backup node are stored in the storage unit, the position information of the master-slave database cluster in the storage unit is updated. At this time, the position information of the failed target node is not stored in the storage unit.
[0071] Therefore, in the embodiment, if the failure of the target node is recovered, the target node can determine whether the database of the target node and the database of the node have a master-slave replication relationship according to the position information in the storage unit. If not, the database of the target node is deleted. If yes, the node and the target node continue to provide database read-write services. For example, Figure 3As shown, the first slave node fails, if the failure of the first slave node has been recovered at this time, the database management service in the first slave node reads the database node location information in the storage unit, if the location information of the first slave node is not found, it means that the first slave node is no longer a slave node of the first master node, then the database instance on the first slave node is closed, and the first slave node at this time can be used as a backup node. As shown in Figure 4 As shown, the second master node fails, if the failure of the second master node has been recovered at this time, the database management service in the second master node reads the database node location information in the storage unit, if the location information of the second master node is not found, it means that the second master node is no longer a master node, then the database instance on the second master node is closed, and the second master node at this time can also be used as a backup node; after being restored as a backup node, it can replace the target node that fails after any node in the master-slave database cluster fails.
[0072] It can be understood that when the database is switched, the database management services on multiple database nodes will be mutually exclusive by adding a distributed lock to ensure that only one node can complete automatic switching. For example, after the master node fails, if the number of slave nodes is multiple, each slave node will detect the failure of the master node, at this time, in order to avoid each slave node selecting a backup node to create a database, a distributed lock can be added to ensure that only one slave node selects a backup node and creates a database, realizing the switching of the failed database.
[0073] As can be seen from the above, in order to realize the high availability of the master-slave database, the present application proposes an automatic operation and maintenance scheme for the master-slave database without data loss. In the present application, after the location information of the master-slave node where the database is located is selected, the database management service in the master-slave node can be run, which is responsible for maintaining the life cycle of the master-slave database cluster, such as starting the database instance in the master-slave node by the database management service, and monitoring the running state of the master-slave database. If an exception occurs in the master-slave database cluster, automatic operation and maintenance disposal is performed to quickly restore the business access of the database and restore the master-slave database cluster to normal; and the database management service stores information about which node in the database stores the latest data in the consistency protocol storage during the life cycle of the master-slave database cluster. Only when the switching of data does not result in data loss, the switching operation of the database is performed, thereby realizing the high availability of the master-slave database without data loss. Further, when the database is automatically operated and maintained, the information in the consistency storage is updated synchronously to ensure the accuracy of the automatic operation and maintenance.
[0074] The processing device, the equipment and the storage medium provided by the embodiments of the present application are introduced below, and the processing device, the equipment and the storage medium described below can be mutually referred to with the processing method described above.
[0075] Referring to Figure 5 The database fault processing device provided by the embodiments of the present application has a structural schematic diagram, which comprises:
[0076] The determining module 21 is configured to determine a target node corresponding to the current node, wherein the database of the current node and the database of the target node have a master-slave replication relationship;
[0077] The creating module 22 is configured to create a database in a backup node when a failure occurs in the target node and the database of the current node stores the latest data.
[0078] The copying module 23 is configured to copy the data in the database of the current node to the database of the backup node.
[0079] The setting module 24 is configured to establish a master-slave replication relationship between the database of the current node and the database of the backup node.
[0080] Based on the above embodiments, in the present embodiment, the database fault processing device further comprises:
[0081] The processing module is configured to cancel the master-slave replication relationship between the database of the current node and the database of the target node before creating the database in the backup node.
[0082] The execution module is configured to provide database read-write services through the first master node when the current node is the first master node and the target node is the first slave node, and to upgrade the second slave node to a third master node and provide database read-write services through the third master node when the current node is the second slave node and the target node is the second master node.
[0083] Based on the above embodiments, in the present embodiment, the creating module 22 is specifically configured to select a third slave node for creating a database from a plurality of backup nodes according to the health status of each backup node.
[0084] Based on the above embodiments, in the present embodiment, the database fault processing device further comprises:
[0085] The detection module is configured to detect whether the first master node / third master node has a non-faulty slave node; if the first master node / third master node does not have a non-faulty slave node, the creation module 22 is triggered to create a database in a backup node; if the first master node / third master node has a non-faulty slave node, the first master node / third master node and the corresponding non-faulty slave node provide database read / write services.
[0086] Based on the above embodiment, in this embodiment, the database fault processing apparatus further comprises:
[0087] The first judgment module is configured to judge whether the current node is in a data consistent state; if yes, it is determined that the database of the current node stores the latest data; if not, the second judgment module is triggered;
[0088] The second judgment module is configured to judge whether the current node is a master node; if yes, it is determined that the database of the current node stores the latest data; if not, it is determined that the database of the current node does not store the latest data.
[0089] Based on the above embodiment, in this embodiment, the database fault processing apparatus further comprises:
[0090] The storage module is configured to store the position information of the current node and the position information of the backup node to the storage unit after establishing the master-slave replication relationship between the database of the current node and the database of the backup node.
[0091] Based on the above embodiment, in this embodiment, the database fault processing apparatus further comprises:
[0092] The third judgment module is configured to, when the fault of the target node has been recovered, judge, according to the position information in the storage unit, whether the target node has a master-slave replication relationship with the database of the current node; if not, delete the database of the target node; if yes, continue to provide database read / write services through the current node and the target node.
[0093] Referring to Figure 6 An electronic device structure schematic diagram disclosed by the embodiment of the present application; the device comprises:
[0094] The memory 31 is configured to store a computer program;
[0095] The processor 32 is configured to execute the computer program to realize the steps of the database fault processing method according to any method embodiment.
[0096] In the embodiment, the device can be a PC (Personal Computer), or a terminal device such as a smart phone, a tablet computer, a palm computer, a portable computer, etc.
[0097] The device can include a memory 31, a processor 32 and a bus 33.
[0098] The memory 31 includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The memory provides an environment for the operating system and computer readable instructions in the non-volatile storage medium to run. The processor 32 can be a central processing unit (CPU), a controller, a microcontroller, a microprocessor or other data processing chip in some embodiments. The processor provides computing and control capabilities for the gateway device and executes the computer program stored in the memory 31 to implement the steps of the database fault processing method disclosed in any of the preceding embodiments.
[0099] The bus 33 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used to represent the bus in the figure, but it does not mean that there is only one bus or only one type of bus.
[0100] Further, the device can also include a network interface 34, which can optionally include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), and is usually used to establish a communication connection between the device and other electronic devices.
[0101] Figure 6 Only the device with components 31-34 is shown, and those skilled in the art can understand that, Figure 6 The structure shown does not constitute a limitation on the device, and can include fewer or more components than shown, or combine certain components, or different component arrangements.
[0102] The embodiment of the application also discloses a computer readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the database fault processing method disclosed in any of the preceding method embodiments are implemented.
[0103] The storage medium can include a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and the like.
[0104] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the difference from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0105] The above description of disclosed embodiments enables those skilled in the art to carry out or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A database failure handling method, characterized by, The database processing method comprises: determining a target node corresponding to the current node; wherein the database of the current node and the database of the target node have a master-slave replication relationship; if a failure of the target node is monitored and the latest data is stored in the database of the current node, creating a database in a backup node, copying the data in the database of the current node to the database of the backup node, and establishing a master-slave replication relationship between the database of the current node and the database of the backup node; wherein the latest data is stored in the database of the current node comprises: judging whether the current node is in a data consistent state; if yes, determining that the latest data is stored in the database of the current node; if no, judging whether the current node is a master node; if the current node is a master node, determining that the latest data is stored in the database of the current node; if the current node is a slave node, determining that the latest data is not stored in the database of the current node.
2. The database failure handling method of claim 1, wherein, The method further comprises, before creating the database in the backup node: canceling the master-slave replication relationship between the database of the current node and the database of the target node; if the current node is a first master node and the target node is a first slave node, providing database read-write services through the first master node; if the current node is a second slave node and the target node is a second master node, promoting the second slave node to a third master node, and providing database read-write services through the third master node.
3. The database failure handling method of claim 2, wherein, The method further comprises, in creating the database in the backup node: selecting a third slave node for creating the database from a plurality of backup nodes according to the health states of the backup nodes.
4. The database failure handling method of claim 2, wherein, After providing the database read-write services through the first master node / third master node, the method further comprises: detecting whether the first master node / third master node has an unfailed slave node; if no, continuing to perform the step of creating the database in the backup node; if yes, providing database read-write services through the first master node / third master node and the corresponding unfailed slave node.
5. The database failure handling method according to any one of claims 1 to 4, characterized by, After establishing the master-slave replication relationship between the database of the current node and the database of the backup node, the method further comprises: storing the location information of the current node and the location information of the backup node to a storage unit.
6. The database failure handling method of claim 5, wherein, The method further comprises: if the failure of the target node has been recovered, judging, by the target node, whether the database of the target node and the database of the current node have a master-slave replication relationship according to the location information in the storage unit; if no, deleting the database of the target node; if yes, continuing to provide database read-write services through the current node and the target node.
7. A database failure handling apparatus characterized by comprising: The method comprises: a determining module configured to determine a target node corresponding to the current node; wherein the database of the current node and the database of the target node have a master-slave replication relationship; a creating module configured to create a database in a backup node when a failure of the target node is monitored and the latest data is stored in the database of the current node; a copying module configured to copy the data in the database of the current node to the database of the backup node. The setting module is configured to establish a master-slave replication relationship between the database of the local node and the database of the backup node. The first judging module is configured to judge whether the local node is in a data consistent state. The second judging module is configured to judge whether the local node is a master node.
8. An electronic device, comprising: The memory is configured to store a computer program. The processor is configured to execute the computer program to implement the steps of the database failure processing method according to any one of claims 1 to 6. The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the steps of the database failure processing method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that,
Citation Information
Patent Citations
Fault processing method and device of database cluster, and terminal
CN108599996A
Node availability management and control method, node, cluster, device and medium
CN113704029A