Database cluster communication exception processing method and device, equipment and storage medium
By monitoring communication connections and active status between the database cluster and the distributed key-value database, and switching the master node in abnormal situations, the problem of low processing efficiency when the database cluster communication is abnormal is solved, and rapid service recovery and stability improvement is achieved.
Patent Information
- Application Number
- CN202411770706.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-11
AI Technical Summary
Database clusters are not efficient in handling communication exceptions, resulting in business interruption and insufficient stability.
By determining the communication connection status between the database cluster and the distributed key-value database, the communication activity status between the master node and the distributed key-value database is obtained, and the master node is switched to restore the data read and write tasks in abnormal situations.
It realizes rapid recovery and business continuity when communication abnormalities of the database cluster are achieved, and improves the risk resistance and business stability of the database cluster.
Smart Images

Figure CN119806916A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of database technology, and in particular to a method and device for handling database cluster communication exceptions. Background Art
[0002] At present, database technology and systems have become the core technology and important foundation of information infrastructure. As the most effective means of data management, database technology has greatly promoted the development of computer applications. Single-center deployment of databases has certain business continuity risks. For example, if force majeure causes the database server to fail, the business connected to the database cluster will be interrupted. Even if there are backups in other centers or regions, recovery will take a long time. In addition, in the current context of high concurrency and massive data, single-center databases have read and write bottlenecks. This leads to poor risk resistance and insufficient scalability of the database.
[0003] In related technologies, cloud-native database technology can be used, with Kubernetes as the operating base, to solve the problem of insufficient scalability caused by the low risk resistance and poor editability of the database cluster by leveraging its elastic scaling and fault self-healing features.
[0004] However, in the above method, if the database communication is abnormal, the business that depends on the data cluster library will be interrupted and crashed. This results in the stability and risk resistance of the database cluster being still low. Summary of the invention
[0005] The embodiments of the present application provide a method, device, system, electronic device and computer-readable storage medium for handling database cluster communication exceptions, so as to solve the problem of low efficiency in handling database cluster communication exceptions in related technologies.
[0006] In a first aspect, an embodiment of the present application provides a method for handling database cluster communication exceptions, the method comprising:
[0007] Determine a first communication connection state between a first database cluster and a first distributed key-value database cluster, and a second communication connection state between a second database cluster and the first distributed key-value database cluster;
[0008] When both the first communication connection state and the second communication connection state are in normal state, based on the first backup node in the first database cluster, obtaining a first communication activity state between the first master node in the first database cluster and the first distributed key-value database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster;
[0009] When the first communication activity state is abnormal, determine from the first backup node a second master node whose communication connection state with the first distributed key-value database cluster is normal, and based on the communication connection between the second master node and the first distributed key-value database cluster, resume execution of the target data reading and writing task.
[0010] Optionally, the method further comprises:
[0011] When the node information update frequencies of the first master node and the first backup node are both zero, a third master node whose communication connection status with the first distributed key-value database cluster is normal is determined from the second database cluster, and based on the communication connection between the third master node and the first distributed key-value database cluster, the target data reading and writing tasks are resumed.
[0012] Optionally, the method further comprises:
[0013] Determine a third communication connection state between the first database cluster and the second distributed key-value database cluster and a fourth communication connection state between the second database cluster and the second distributed key-value database cluster;
[0014] When the first communication connection state is in an abnormal state, and the third communication connection state and the fourth communication connection state are both in normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a third communication connection between the first master node and the second distributed key-value database cluster;
[0015] Based on the third communication connection, the target data reading and writing task is resumed.
[0016] Optionally, resuming execution of the target data reading and writing task based on the third communication connection includes:
[0017] Based on the third communication connection, obtaining a second communication activity state between the first master node and the second distributed key-value database cluster;
[0018] When the second communication activity state is abnormal, determine from the first backup node a fourth master node whose communication connection state with the second distributed key-value database cluster is normal, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, resume execution of the target data reading and writing task.
[0019] Optionally, the method further comprises:
[0020] When the second communication connection is in an abnormal state, and the first communication connection state, the third communication connection state, and the fourth communication connection state are all in normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a fourth communication connection between the first master node and the second distributed key-value database cluster;
[0021] Based on the fourth communication connection, the target data reading and writing task is resumed.
[0022] Optionally, the communication connection between the first master node and the first distributed key-value database cluster includes a distributed lock.
[0023] Optionally, the method further comprises:
[0024] When the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all in abnormal states, fault prompt information is sent to a target user corresponding to the target data reading and writing task.
[0025] In a second aspect, an embodiment of the present application provides a database cluster communication exception processing device, the device comprising:
[0026] A first determining module, configured to determine a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster;
[0027] an acquisition module, configured to acquire, when both the first communication connection state and the second communication connection state are in normal states, a first communication activity state between a first master node in the first database cluster and the first distributed key-value database cluster based on a first backup node in the first database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster;
[0028] The first determination recovery module is used to determine, when the first communication activity state is abnormal, a second master node whose communication connection state with the first distributed key-value database cluster is normal from the first backup node, and resume execution of the target data reading and writing task based on the communication connection between the second master node and the first distributed key-value database cluster.
[0029] Optionally, the device further comprises:
[0030] The second determination recovery module is used to determine a third master node whose communication connection status with the first distributed key-value database cluster is in a normal state from the second database cluster when the node information update frequencies of the first master node and the first backup node are both zero, and based on the communication connection between the third master node and the first distributed key-value database cluster, resume execution of the target data reading and writing tasks.
[0031] Optionally, the device further comprises:
[0032] A second determination module, configured to determine a third communication connection state between the first database cluster and the second distributed key-value database cluster and a fourth communication connection state between the second database cluster and the second distributed key-value database cluster;
[0033] A first cancellation creation module is used to cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and to create a third communication connection between the first master node and the second distributed key-value database cluster when the first communication connection state is an abnormal state and the third communication connection state and the fourth communication connection state are both normal states;
[0034] The first recovery module is used to recover the target data reading and writing task based on the third communication connection.
[0035] Optionally, the first recovery module includes:
[0036] an acquisition submodule, configured to acquire, based on the third communication connection, a second communication activity state between the first master node and the second distributed key-value database cluster;
[0037] A recovery submodule is determined, which is used to determine, from the first backup node, a fourth master node whose communication connection status with the second distributed key-value database cluster is in a normal state when the second communication activity status is in an abnormal state, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, resume execution of the target data reading and writing task.
[0038] Optionally, the device further comprises:
[0039] a second cancellation creation module, configured to cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and to create a fourth communication connection between the first master node and the second distributed key-value database cluster when the second communication connection is in an abnormal state and the first communication connection state, the third communication connection state and the fourth communication connection state are all in normal states;
[0040] The second recovery module is used to recover the target data reading and writing task based on the fourth communication connection.
[0041] Optionally, the communication connection between the first master node and the first distributed key-value database cluster includes a distributed lock.
[0042] Optionally, the device further comprises:
[0043] A sending module is used to send fault prompt information to a target user corresponding to the target data reading and writing task when the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all abnormal states.
[0044] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement any of the database cluster communication exception handling methods described above.
[0045] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any of the database cluster communication exception handling methods described above.
[0046] In an embodiment of the present application, a method for handling database cluster communication anomalies is provided, including: determining a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster, and when both the first communication connection state and the second communication connection state are in normal states, obtaining a first communication activity state between a first master node in the first database cluster and the first distributed key-value database cluster based on a first backup node in the first database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster, and when the first communication activity state is in an abnormal state, determining from the first backup node that the communication connection state with the first distributed key-value database cluster is in a normal state. Second master node, and based on the communication connection between the second master node and the first distributed key-value database cluster, the target data reading and writing task is restored. When the first communication connection state between the first database cluster and the first distributed key-value database cluster and the second communication connection state between the second database cluster and the first distributed key-value database cluster are in a normal state, the first communication activity state between the first master node and the first distributed key-value database cluster is obtained, and when the first communication activity state is in an abnormal state, the second master node can be determined from the first backup node of the first database cluster, so that the target data reading and writing task can be restored. When the communication between the database clusters is abnormal, the connection between the master node and the distributed key-value database cluster can be switched in time, so that the target data reading and writing task can continue to be executed, which improves the risk resistance of the database cluster to a certain extent and improves the stability of the database cluster business.
[0047] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0049] Figure 1 It is a flowchart of the steps of a method for handling database cluster communication exceptions provided in an embodiment of the present application;
[0050] Figure 2 It is a flowchart of another method for handling database cluster communication exceptions provided in an embodiment of the present application;
[0051] Figure 3 It is a schematic diagram of a database cluster architecture provided in an embodiment of the present application;
[0052] Figure 4 It is a logic block diagram of a database cluster communication exception handling device provided in an embodiment of the present application;
[0053] Figure 5 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.
[0055] Figure 1 This is a flowchart of a method for handling database cluster communication exceptions provided by an embodiment of the present application, which is applied to the server, such as Figure 1 As shown, the method includes:
[0056] Step 101: determine a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster.
[0057] In an embodiment of the present application, the first database cluster and the second database cluster can be used to store specific data, and can have read and write functions, such as the postgres database cluster in kubernetes. The second database cluster can be a standby database cluster for the first database cluster. When the first database cluster reads and writes data, it can be copied to the second database cluster through a data stream. In addition, the first distributed key-value database cluster can maintain a communication connection with the first database cluster and the second database cluster to form a database cluster architecture. In the first distributed key-value database, the key-value pairs of each data in the first database cluster can be saved, wherein the first distributed key-value database can be a Redis database, a DynamoDB database, an etcd database, etc. Through the key-value pair, the desired target data can be quickly found. On this basis, the first communication connection state between the first database cluster and the first distributed key-value database cluster and the second communication connection state between the second database cluster and the first distributed key-value database cluster can be determined. For example, a test signal may be sent to determine the first communication connection state and the second communication connection state, or the first communication connection state and the second communication connection state may be determined based on whether there is communication activity in the first communication connection between the first database cluster and the first distributed key-value database cluster, and whether there is communication activity in the second communication connection between the second database cluster and the first distributed key-value database cluster.
[0058] Step 102, when the first communication connection state and the second communication connection state are both in normal states, based on the first backup node in the first database cluster, obtain the first communication activity state between the first master node in the first database cluster and the first distributed key-value database cluster; wherein the first communication activity state is based on the communication connection between the first master node and the first distributed key-value database cluster, and is generated when executing the target data reading and writing task.
[0059] In an embodiment of the present application, in the first database cluster, multiple task nodes may be included, and one of the nodes may be used as the first master node for data flow with the first distributed key-value database cluster to perform the target data read and write task. The target data read and write task may be performed by the database cluster architecture consisting of the first database cluster, the second database cluster and the first distributed key-value database cluster. In the first database cluster, other task nodes may be used as backup nodes of the master node, and the communication status between the master node and the first distributed key-value database cluster may be obtained. Each node in the second database cluster may also obtain the communication status between the master node and the first distributed key-value database cluster. On this basis, if the first communication connection status between the first database cluster and the first distributed key-value database cluster, and the second communication connection status between the second database cluster and the first distributed key-value database cluster are both in normal states, the first communication activity status between the first master node in the first database cluster and the first distributed key-value database cluster may be obtained through the first backup node in the first database cluster, wherein the first communication activity status may be generated when the target data read and write task is performed through the communication connection between the first master node and the first distributed key-value database cluster. If the first master node can perform normal data flow activities with the first distributed key-value database cluster, the first communication activity state is a normal state; if the first master node cannot perform normal data flow activities with the first distributed key-value database cluster, the first communication activity state is an abnormal state.
[0060] For example, if the first database cluster is a postgres database cluster and the first distributed key-value database cluster is an etcd cluster, the deployment conditions and parameters for a one-master and five-slave postgres database cluster in the same city are as follows:
[0061] 1. etcd cluster deployment requires that the etcd cluster and the two data centers are reachable;
[0062] 2. Local data center controller (operator) and postgres database cluster deployment
[0063] Operator deployment, the relevant configuration parameters are as follows:
[0064]
[0065]
[0066] Postgres instance deployment, the relevant configuration parameters are as follows:
[0067]
[0068] 3. Operator deployment of the postgres database cluster in the same city. The relevant configuration parameters are as follows:
[0069]
[0070]
[0071] Postgres instance deployment, the relevant configuration parameters are as follows:
[0072]
[0073]
[0074] Among them, "same city" corresponds to the second database cluster, and "local" corresponds to the first database cluster.
[0075] Step 103, when the first communication activity state is in an abnormal state, determine from the first backup node a second master node whose communication connection state with the first distributed key-value database cluster is in a normal state, and based on the communication connection between the second master node and the first distributed key-value database cluster, resume execution of the target data reading and writing task.
[0076] In an embodiment of the present application, the communication activity status may refer to whether there is data flow activity in the communication connection. If so, the communication activity status may be defined as a normal status. If not, the communication activity status may be defined as an abnormal status. If the first communication activity status is an abnormal status, it means that the first master node cannot perform normal data communication activities with the first distributed key-value database cluster, and the target data read and write task is in a stagnant state. In this case, a second master node whose communication connection with the first distributed key-value database cluster is in a normal state may be determined from the first backup node, so that the target data read and write task may be resumed through the communication connection between the second master node and the first distributed key-value database cluster. Among them, if there are multiple first backup nodes that meet the above conditions, one may be selected as the second master node from the first backup nodes that meet the above conditions by random selection.
[0077] In summary, a method for handling database cluster communication anomalies provided in an embodiment of the present application includes: determining a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster, and when both the first communication connection state and the second communication connection state are in normal states, obtaining a first communication activity state between a first master node in the first database cluster and the first distributed key-value database cluster based on a first backup node in the first database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster, and when the first communication activity state is in an abnormal state, determining from the first backup node that the communication connection state with the first distributed key-value database cluster is in a normal state. The second master node is used to restore the target data reading and writing task based on the communication connection between the second master node and the first distributed key-value database cluster. The first communication activity state between the first master node and the first distributed key-value database cluster can be obtained when the first communication connection state between the first database cluster and the first distributed key-value database cluster and the second communication connection state between the second database cluster and the first distributed key-value database cluster are in a normal state. The second master node can be determined from the first backup node of the first database cluster when the first communication activity state is in an abnormal state, so that the target data reading and writing task can be restored. When the communication between the database clusters is abnormal, the connection between the master node and the distributed key-value database cluster can be switched in time, so that the target data reading and writing task can continue to be executed, which improves the risk resistance of the database cluster to a certain extent and improves the stability of the database cluster business.
[0078] like Figure 2 As shown, Figure 2 is a flowchart of another method for handling database cluster communication exceptions provided by an embodiment of the present application. The method may include:
[0079] Step 201: determine a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster.
[0080] In the embodiments of the present application, the implementation content of this step can refer to the embodiment content of step 101, which will not be repeated here.
[0081] Step 202, when the first communication connection state and the second communication connection state are both in normal states, based on the first backup node in the first database cluster, obtain the first communication activity state between the first master node in the first database cluster and the first distributed key-value database cluster; wherein the first communication activity state is based on the communication connection between the first master node and the first distributed key-value database cluster, and is generated when executing the target data reading and writing task.
[0082] In the embodiments of the present application, the implementation content of this step can refer to the implementation content of step 102, which will not be repeated here.
[0083] Optionally, the communication connection between the first master node and the first distributed key-value database cluster includes a distributed lock.
[0084] In an embodiment of the present application, the communication connection between the first master node and the first distributed key-value database cluster may include a distributed lock, that is, the communication connection between the first master node and the first distributed key-value database cluster is locked through a distributed lock. In this way, the communication activity between the first master node and the first distributed key-value database cluster will be locked when executing the target data reading and writing tasks, thereby ensuring the stability of the execution of the target data reading and writing tasks.
[0085] Step 203, when the first communication activity state is in an abnormal state, determine from the first backup node a second master node whose communication connection state with the first distributed key-value database cluster is in a normal state, and based on the communication connection between the second master node and the first distributed key-value database cluster, resume execution of the target data reading and writing task.
[0086] In the embodiments of the present application, the implementation content of this step can refer to the implementation content of step 103, which will not be repeated here.
[0087] Step 204, when the node information update frequencies of the first master node and the first backup node are both zero, determine from the second database cluster a third master node whose communication connection status with the first distributed key-value database cluster is in a normal state, and based on the communication connection between the third master node and the first distributed key-value database cluster, resume execution of the target data reading and writing task.
[0088] In an embodiment of the present application, the first master node and the first backup node in the first database cluster may have a certain node information update frequency, i.e., a heartbeat mechanism, and the node information may include the execution log of the target data read and write task. If the above node information update frequency is 0, it means that the first master node has stopped the communication activity with the first distributed key-value database cluster, i.e., the target data read and write task is in a stagnant state, and the first backup node is also unable to obtain the first communication activity state between the first master node and the first distributed key-value database cluster. At this time, it can be considered that the first database cluster is in a downtime state. In this case, the second database cluster can be used as the main cluster, and the third master node whose communication connection with the first distributed key-value database cluster is in a normal state can be obtained from the second database cluster, so that the target data read and write task can be resumed through the communication connection between the third master node and the first distributed key-value database cluster.
[0089] In an embodiment of the present application, by determining, from the second database cluster, a third master node whose communication connection status with the first distributed key-value database cluster is in a normal state when the node information update frequencies of the first master node and the first backup node are both zero, and based on the communication connection between the third master node and the first distributed key-value database cluster, resuming execution of the target data reading and writing tasks, it is possible to determine, from the second database cluster, a third master node that meets the conditions when the communication connections between the first master node and the first backup node in the first database cluster and the first distributed key-value database cluster are both in an abnormal state, and resume execution of the target data reading and writing tasks through the communication connection between the third master node and the first distributed key-value database cluster, which can avoid, to a certain extent, the interruption of the target data reading and writing tasks caused by network anomalies, thereby improving the stability and risk resistance of the database cluster.
[0090] Step 205: Determine a third communication connection state between the first database cluster and the second distributed key-value database cluster and a fourth communication connection state between the second database cluster and the second distributed key-value database cluster.
[0091] In an embodiment of the present application, the cluster type of the second distributed key-value database cluster and the first distributed key-value database cluster can be the same, and the second distributed key-value database cluster can be used as a backup cluster for the first distributed key-value database cluster. For other implementation contents of this step, please refer to the embodiment contents of step 101, which will not be repeated here.
[0092] Step 206, when the first communication connection state is an abnormal state, and the third communication connection state and the fourth communication connection state are both normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a third communication connection between the first master node and the second distributed key-value database cluster.
[0093] In an embodiment of the present application, if the first communication connection is in an abnormal state, and the third communication connection between the first database cluster and the second distributed key-value database and the fourth communication connection between the second database cluster and the second distributed key-value database cluster are in a normal state, it means that the first database cluster is no longer able to transfer data with the first distributed key-value database cluster. In this case, the first communication connection between the first database cluster and the first distributed key-value database cluster and the second communication connection between the second database cluster and the first distributed key-value database cluster can be cancelled, and at the same time, the third communication connection between the first master node in the first database cluster and the second distributed key-value database cluster is created. In addition, a communication connection between the first backup node and the second distributed key-value database cluster and a communication connection between all nodes in the second database cluster and the second distributed key-value database cluster can also be created, so that the first backup node and the second database cluster can monitor the communication activities between the first master node and the second distributed key-value database cluster.
[0094] For example, Figure 3 As shown, Figure 3A schematic diagram of a database cluster architecture provided for an embodiment of the present application. In the figure, the database cluster architecture may include two database clusters, namely a first database cluster and a second database cluster, and may also include two distributed key-value database clusters, namely a first distributed key-value database cluster and a second distributed key-value database cluster. The first database cluster is the main database cluster, the first distributed key-value database cluster is the main key-value cluster, and the second database cluster and the second distributed key-value database cluster are both standby clusters. In the first database cluster, the master node can communicate with the cluster nodes in the first distributed key-value database cluster to perform data reading and writing tasks. At the same time, the standby nodes in the first database cluster and the standby nodes in the second database cluster can monitor the communication activities between the master node and the cluster nodes, and the master node can also synchronize the data reading and writing status of the master node to each standby node in an asynchronous manner. If the master node in the first database cluster and the cluster nodes in the first distributed key-value database cluster cannot communicate, and other backup nodes cannot normally monitor the communication status between the master node and the cluster nodes, that is, the first communication connection between the first database cluster and the first distributed key-value database cluster is in an abnormal state, and the communication connection between the second database cluster and the second distributed key-value database cluster and the communication connection between the first database cluster and the second distributed key-value database cluster are both in normal states, in this case, the communication connection between the first database cluster and the first distributed key-value database cluster can be cancelled, and the communication connection between the second database cluster and the first distributed key-value database cluster can be cancelled, and a third communication connection between the master node and the second distributed key-value database cluster can be created. At the same time, each backup node can also establish a communication connection with the second distributed key-value database cluster to monitor the communication activity status of the third communication connection.
[0095] Step 207: Resume executing the target data reading and writing task based on the third communication connection.
[0096] In an embodiment of the present application, the target data read and write task can be resumed according to the third communication connection. At this time, the communication connection state between the first master node and the second distributed key-value database cluster is normal, the master node can maintain a normal node update frequency, and can send the master node information to each backup node in an asynchronous manner.
[0097] Optionally, step 207 may include the following sub-steps:
[0098] Sub-step 2071: Based on the third communication connection, obtain a second communication activity state between the first master node and the second distributed key-value database cluster.
[0099] In an embodiment of the present application, the second communication activity state between the first master node and the second distributed key-value database cluster can be obtained based on the third communication connection. The second communication activity state is the communication state of the communication activity corresponding to the sixth communication connection, which can be obtained by each backup node monitoring the sixth communication connection.
[0100] Sub-step 2072, when the second communication activity state is in an abnormal state, determine from the first backup node a fourth master node whose communication connection state with the second distributed key-value database cluster is in a normal state, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, resume execution of the target data reading and writing task.
[0101] In an embodiment of the present application, if the second communication activity state is an abnormal state, a fourth master node whose communication connection with the second distributed key-value database cluster is in a normal state can be determined from the first backup node, so that the target data reading and writing tasks can be restored based on the communication connection between the fourth master node and the second distributed key-value database cluster.
[0102] In an embodiment of the present application, by obtaining the second communication activity status between the first master node and the second distributed key-value database cluster based on the third communication connection, when the second communication activity status is in an abnormal state, a fourth master node whose communication connection status with the second distributed key-value database cluster is in a normal state is determined from the first backup node, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, the target data reading and writing tasks are restored. In the case where the second communication activity status between the first master node and the second distributed key-value database cluster is in an abnormal state, a fourth master node that meets the conditions can be determined from the first backup node, and the target data reading and writing tasks can be restored through the communication connection between the fourth master node and the second distributed key-value database cluster, which improves the stability and risk resistance of the database cluster to a certain extent.
[0103] In an embodiment of the present application, when the first communication connection state is in an abnormal state and the third communication connection state and the fourth communication connection state are both in normal states, the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster are cancelled, and a third communication connection between the first master node and the second distributed key-value database cluster is created. Based on the third communication connection, the target data reading and writing task is restored. When the first communication connection is in an abnormal state and the first communication connection and the third communication connection between the first database cluster and the second distributed key-value database cluster and the fourth communication connection between the second database cluster and the second distributed key-value database cluster are all in normal states, the second distributed key-value database cluster is enabled, and the target data reading and writing task is restored through the communication connection between the first master node and the second distributed key-value database. The target data reading and writing task can be kept from being interrupted without switching the database cluster from master to slave, thereby improving the stability and risk resistance of the database cluster to a certain extent.
[0104] Step 208, when the second communication connection is in an abnormal state, and the first communication connection state, the third communication connection state and the fourth communication connection state are all in normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a fourth communication connection between the first master node and the second distributed key-value database cluster.
[0105] In an embodiment of the present application, if the second communication connection is in an abnormal state, and the first communication connection state, the third communication connection state, and the fourth communication connection state are all in normal states, the second database cluster cannot monitor the communication activities between the first master node and the first distributed key-value database cluster. In this case, the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster can be cancelled, and a fourth communication connection between the first master node and the second distributed key-value database cluster can be created. After the second communication connection is cancelled, the communication connection between the first master node and the first backup node and the first distributed key-value database cluster is disconnected, and communication activities cannot be performed.
[0106] Step 209: Resume executing the target data reading and writing task based on the fourth communication connection.
[0107] In the embodiment of the present application, the target data reading and writing task can be resumed based on the fourth communication connection, wherein the fourth communication connection has the same function as the third communication connection, and the embodiment of step 207 can be referred to, which will not be described here.
[0108] In an embodiment of the present application, by canceling the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster when the second communication connection is in an abnormal state and the first communication connection state, the third communication connection state and the fourth communication connection state are all in normal states, and creating a fourth communication connection between the first master node and the second distributed key-value database cluster, based on the fourth communication connection, the target data reading and writing tasks are restored. When the second communication connection state is in an abnormal state and the first communication connection state, the third communication connection state and the fourth communication connection state are all in normal states, the second distributed key-value database cluster can be enabled, and the target data reading and writing tasks can be restored through the communication connection between the first master node and the second distributed key-value database cluster, thereby improving the stability and risk resistance of the database cluster to a certain extent.
[0109] Step 210: When the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all in abnormal states, a fault prompt message is sent to a target user corresponding to the target data reading and writing task.
[0110] In an embodiment of the present application, if the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all abnormal states, the database cluster architecture cannot restore the execution of the target data reading and writing tasks by switching the database cluster and the distributed key-value database cluster. At this time, a fault prompt information can be sent to the target user corresponding to the target data reading and writing task so that human intervention can be performed to repair the cluster failure.
[0111] In an embodiment of the present application, by sending fault prompt information to the target user corresponding to the target data reading and writing task when the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all in abnormal states, fault prompt information can be sent to the target user when each communication connection state is in an abnormal state, which can avoid the serious crash consequences that may be caused by the program falling into an infinite loop, thereby improving the stability of the database cluster to a certain extent.
[0112] In an embodiment of the present application, the above-mentioned database cluster communication exception handling method can be executed by a single controller or by multiple controllers in conjunction. For example, if the first database cluster includes a master controller and the second database cluster includes a slave controller, the master controller can send a notification to the slave controller after switching the first database cluster from connecting to the first distributed key-value database cluster to connecting to the second distributed key-value database cluster. After receiving the notification message, the slave controller can switch the second database cluster from connecting to the first distributed key-value database cluster to connecting to the second distributed key-value database cluster, so that the first database cluster and the second database cluster can always be connected to the same distributed key-value database cluster.
[0113] like Figure 4 As shown, Figure 4 A logical block diagram of a database cluster communication exception handling device provided by the present application, the device 400 includes:
[0114] A first determining module 401 is used to determine a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster;
[0115] The acquisition module 402 is used to acquire, when both the first communication connection state and the second communication connection state are in normal states, a first communication activity state between a first master node in the first database cluster and the first distributed key-value database cluster based on a first backup node in the first database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster;
[0116] The first determination recovery module 403 is used to determine, when the first communication activity state is abnormal, a second master node whose communication connection state with the first distributed key-value database cluster is normal from the first backup node, and resume execution of the target data reading and writing task based on the communication connection between the second master node and the first distributed key-value database cluster.
[0117] Optionally, the device 400 further includes:
[0118] The second determination recovery module is used to determine a third master node whose communication connection status with the first distributed key-value database cluster is in a normal state from the second database cluster when the node information update frequencies of the first master node and the first backup node are both zero, and based on the communication connection between the third master node and the first distributed key-value database cluster, resume execution of the target data reading and writing tasks.
[0119] Optionally, the device 400 further includes:
[0120] A second determination module, configured to determine a third communication connection state between the first database cluster and the second distributed key-value database cluster and a fourth communication connection state between the second database cluster and the second distributed key-value database cluster;
[0121] A first cancellation creation module is used to cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and to create a third communication connection between the first master node and the second distributed key-value database cluster when the first communication connection state is an abnormal state and the third communication connection state and the fourth communication connection state are both normal states;
[0122] The first recovery module is used to recover the target data reading and writing task based on the third communication connection.
[0123] Optionally, the first recovery module includes:
[0124] an acquisition submodule, configured to acquire, based on the third communication connection, a second communication activity state between the first master node and the second distributed key-value database cluster;
[0125] A recovery submodule is determined, which is used to determine, from the first backup node, a fourth master node whose communication connection status with the second distributed key-value database cluster is in a normal state when the second communication activity status is in an abnormal state, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, resume execution of the target data reading and writing task.
[0126] Optionally, the device 400 further includes:
[0127] a second cancellation creation module, configured to cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and to create a fourth communication connection between the first master node and the second distributed key-value database cluster when the second communication connection is in an abnormal state and the first communication connection state, the third communication connection state and the fourth communication connection state are all in normal states;
[0128] The second recovery module is used to recover the target data reading and writing task based on the fourth communication connection.
[0129] Optionally, the communication connection between the first master node and the first distributed key-value database cluster includes a distributed lock.
[0130] Optionally, the device 400 further includes:
[0131] A sending module is used to send fault prompt information to a target user corresponding to the target data reading and writing task when the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all abnormal states.
[0132] The database cluster communication exception handling device in the embodiment of the present application can be an electronic device, or a component in an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a GPUBOX, a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0133] The database cluster communication exception handling device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, a Linux operating system, a Windows operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0134] The database cluster communication exception processing device provided in the embodiment of the present application can achieve Figures 1 to 3 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0135] The present application embodiment provides an electronic device, see Figure 5 The electronic device 50 includes: a processor 501, a memory 502, and a computer program 5021 stored in the memory 502 and executable on the processor 501. When the processor 501 executes the program, the database cluster communication exception handling method of the aforementioned embodiment is implemented.
[0136] The embodiment of the present application also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the steps in the database cluster communication exception handling method disclosed in the embodiment of the present application are implemented.
[0137] The embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the processor is enabled to implement the steps in the database cluster communication exception handling method disclosed in the embodiment of the present application.
[0138] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0139] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, apparatuses, electronic devices, and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0140] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0141] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0142] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0143] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0144] The above is a detailed introduction to a database cluster communication exception handling method provided by the present application. This article uses specific examples to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for handling database cluster communication exceptions, characterized in that: The method comprises: Determine a first communication connection state between a first database cluster and a first distributed key-value database cluster, and a second communication connection state between a second database cluster and the first distributed key-value database cluster; When both the first communication connection state and the second communication connection state are in normal state, based on the first backup node in the first database cluster, obtaining a first communication activity state between the first master node in the first database cluster and the first distributed key-value database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster; When the first communication activity state is abnormal, determine from the first backup node a second master node whose communication connection state with the first distributed key-value database cluster is normal, and based on the communication connection between the second master node and the first distributed key-value database cluster, resume execution of the target data reading and writing task.
2. The method according to claim 1, characterized in that: The method further comprises: When the node information update frequencies of the first master node and the first backup node are both zero, a third master node whose communication connection status with the first distributed key-value database cluster is normal is determined from the second database cluster, and based on the communication connection between the third master node and the first distributed key-value database cluster, the target data reading and writing tasks are resumed.
3. The method according to claim 1, characterized in that The method further comprises: Determine a third communication connection state between the first database cluster and the second distributed key-value database cluster and a fourth communication connection state between the second database cluster and the second distributed key-value database cluster; When the first communication connection state is in an abnormal state, and the third communication connection state and the fourth communication connection state are both in normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a third communication connection between the first master node and the second distributed key-value database cluster; Based on the third communication connection, the target data reading and writing task is resumed.
4. The method according to claim 3, characterized in that The resuming execution of the target data reading and writing task based on the third communication connection includes: Based on the third communication connection, obtaining a second communication activity state between the first master node and the second distributed key-value database cluster; When the second communication activity state is abnormal, determine from the first backup node a fourth master node whose communication connection state with the second distributed key-value database cluster is normal, and based on the communication connection between the fourth master node and the second distributed key-value database cluster, resume execution of the target data reading and writing task.
5. The method according to claim 3, characterized in that: The method further comprises: When the second communication connection is in an abnormal state, and the first communication connection state, the third communication connection state, and the fourth communication connection state are all in normal states, cancel the first communication connection between the first database cluster and the first distributed key-value database cluster, and the second communication connection between the second database cluster and the first distributed key-value database cluster, and create a fourth communication connection between the first master node and the second distributed key-value database cluster; Based on the fourth communication connection, the target data reading and writing task is resumed.
6. The method according to claim 1, characterized in that The communication connection between the first master node and the first distributed key-value database cluster includes a distributed lock.
7. The method according to claim 3, characterized in that The method further comprises: When the first communication connection state, the second communication connection state, the third communication connection state and the fourth communication connection state are all in abnormal states, fault prompt information is sent to a target user corresponding to the target data reading and writing task.
8. A database cluster communication exception handling device, characterized in that: The device comprises: A first determining module, configured to determine a first communication connection state between a first database cluster and a first distributed key-value database cluster and a second communication connection state between a second database cluster and the first distributed key-value database cluster; an acquisition module, configured to acquire, when both the first communication connection state and the second communication connection state are in normal states, a first communication activity state between a first master node in the first database cluster and the first distributed key-value database cluster based on a first backup node in the first database cluster; wherein the first communication activity state is generated when executing a target data read and write task based on the communication connection between the first master node and the first distributed key-value database cluster; The first determination recovery module is used to determine, when the first communication activity state is abnormal, a second master node whose communication connection state with the first distributed key-value database cluster is normal from the first backup node, and resume execution of the target data reading and writing task based on the communication connection between the second master node and the first distributed key-value database cluster.
9. An electronic device, characterized in that: include: processor; A memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the database cluster communication exception handling method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the database cluster communication exception handling method according to any one of claims 1 to 7 is implemented.