High-availability autonomous switching method and device, storage medium and electronic equipment
By autonomously switching to a candidate node when a database slave node detects a failure of the master node and introducing a voting mechanism for the arbitration service node, the problem of failing to elect a new master node under conditions of a majority failure of even-numbered nodes is solved, thus achieving high availability and data consistency assurance for the database system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-16
- Publication Date
- 2026-03-27
Smart Images

Figure CN121750429A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, and particularly relates to a high-availability autonomous switching method and device, a storage medium and an electronic device. BACKGROUND
[0002] With the continuous improvement of enterprise digitization and business online, the database system has become the core component of the key business system, and its high-availability capability directly affects business continuity. In the financial, communication, energy, medical and other industries, once the database fails for a long time, it may cause serious business interruption, data inconsistency and even significant economic losses, so it is of great significance to ensure that the database can still run stably under node failure.
[0003] The existing database high-availability system is usually based on a consensus protocol such as RAFT, and realizes the failure switching of the master node through the majority election. However, the majority mechanism requires more than half of the nodes in the cluster to be alive to complete the election. In the even number of node configuration (for example, 2 nodes, 4 nodes), when exactly half of the nodes fail, the remaining nodes cannot form a majority, resulting in the stagnation of the master election process and the loss of write service capability of the cluster. In addition, to make up for the election deadlock, some traditional solutions introduce fixed arbitration nodes, but the arbitration nodes as a separate judgment source are easy to form a new single-point risk, and lack an effective verification mechanism for the state of the original master node, which is easy to cause security risks such as wrong master switching or double master. SUMMARY
[0004] The present application provides a high-availability autonomous switching method and device, a storage medium and an electronic device to solve the technical problem that the election cannot be completed under the half failure of the even number of nodes.
[0005] In a first aspect, the application provides a method for high-availability autonomous switchover, applied to any slave node in a database cluster, comprising: updating a node state of an original master node as an abnormal node when a proxy component of a target slave node fails to receive a heartbeat packet sent by a proxy component of the original master node within a timeout period or when the received heartbeat packet indicates that a database process of the original master node is unavailable, wherein the target slave node is any slave node in the database cluster; converting the target slave node into a candidate node and initiating a voting request to other available slave nodes in the database cluster to enable each available slave node to participate in voting; initiating an arbitration voting request to an arbitration service node independently deployed in the database cluster when a number of favorable votes obtained is half of a total number of votes, to enable the arbitration service node to vote based on the node state of the original master node and cluster information; and performing incremental data complement to a latest GTID node and converting into a new master node when a favorable vote of the arbitration service node is obtained, wherein the latest GTID node is a node in the database cluster that has executed a largest range of transactions.
[0006] In a second aspect, the application provides a device for high-availability autonomous switchover, applied to any slave node in a database cluster, comprising: an updating module configured to update a node state of an original master node as an abnormal node when a proxy component of a target slave node fails to receive a heartbeat packet sent by a proxy component of the original master node within a timeout period or when the received heartbeat packet indicates that a database process of the original master node is unavailable, wherein the target slave node is any slave node in the database cluster; a first voting module configured to convert the target slave node into a candidate node and initiate a voting request to other available slave nodes in the database cluster to enable each available slave node to participate in voting; a second voting module configured to initiate an arbitration voting request to an arbitration service node independently deployed in the database cluster when a number of favorable votes obtained is half of a total number of votes, to enable the arbitration service node to vote based on the node state of the original master node and cluster information; and a switching module configured to perform incremental data complement to a latest GTID node and convert into a new master node when a favorable vote of the arbitration service node is obtained, wherein the latest GTID node is a node in the database cluster that has executed a largest range of transactions.
[0007] As an optional example, the first voting module comprises: a first voting unit configured to send a voting request containing state information of the target slave node to each available slave node, so that each available slave node receiving the voting request decides voting intention according to its own state information and the state information of the target slave node, wherein the state information comprises term number, log information and priority; and a second voting unit configured to make the target slave node receive voting requests from other candidate nodes and participate in voting, so that each node in the database cluster is both a voting initiator and a voting participant in the voting process.
[0008] As an optional example, the first voting unit comprises: a voting sub-unit configured to compare the state information of each available slave node receiving the voting request with the state information of the target slave node, and vote in favor if the term number of the target slave node is greater than its own term number or the priority of the target slave node is higher than its own priority, and vote against if the term number of the target slave node is less than or equal to its own term number or the priority of the target slave node is lower than its own priority and its own database process is available.
[0009] As an optional example, the second voting module comprises: a third voting unit configured to initiate an arbitration voting request to the arbitration service node, so that the arbitration service node calls a database probe command to confirm the node state of the original master node according to the cluster node list provided by the target slave node and the current cluster configuration information, and votes against if the original master node is confirmed to be in normal operation, and votes in favor if the original master node is confirmed to be abnormal or unreachable.
[0010] As an optional example, the switching module comprises: a determination unit configured to take the node with the largest range of executed transactions in the database cluster as the latest GTID node; an acquisition unit configured to request the latest GTID node to acquire incremental data since its last synchronized log position; and an application unit configured to apply the incremental data to its own database.
[0011] As an optional example, the arbitration service node is independently deployed in the database cluster based on a standard REST interface, does not store business data, and is only used to receive arbitration voting requests, confirm the state of the original master node, and vote on the master election request of the candidate node.
[0012] In a third aspect, the application provides a high-availability autonomous switching system applied to a database cluster, comprising a primary node and a proxy component thereof, a plurality of slave nodes and proxy components thereof, and an arbitration service node independently deployed in the database cluster; the proxy component of the primary node is configured to periodically send a heartbeat packet to the proxy component of each slave node in the database cluster; the proxy component of a target slave node is configured to receive the heartbeat packet sent by the proxy component of the primary node; when the proxy component of the target slave node does not receive the heartbeat packet within a timeout period or the received heartbeat packet indicates that the database process of the primary node is unavailable, the target slave node is configured to update the node state of the primary node to an abnormal node, wherein the target slave node is any one of the plurality of slave nodes; the target slave node is further configured to convert itself into a candidate node and initiate a voting request to other available slave nodes so as to enable the available slave nodes to participate in voting; the target slave node is further configured to initiate an arbitration voting request to the arbitration service node when the number of favorable votes obtained is half of the total number of votes; the arbitration service node is configured to receive the arbitration voting request initiated by the target slave node and perform voting based on the node state of the primary node and cluster information; and the target slave node is further configured to perform incremental data complement to the latest GTID node and convert itself into a new primary node when favorable votes of the arbitration service node are obtained, wherein the latest GTID node is a node in the database cluster that has executed the largest range of transactions.
[0013] In a fourth aspect, the application provides a storage medium having a computer program stored therein, wherein the computer program is configured to perform the high-availability autonomous switching method when executed by a processor.
[0014] In a fifth aspect, the application further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to perform the high-availability autonomous switching method by executing the computer program.
[0015] Compared with the prior art, the above technical solution provided by the embodiments of the application has the following advantages: The application adopts the method of updating the node state of the original master node to an abnormal node when the proxy component of the target slave node does not receive the heartbeat packet sent by the proxy component of the original master node in the database cluster or the received heartbeat packet indicates that the database process of the original master node is unavailable, wherein the target slave node is any slave node in the database cluster; the target slave node is converted into a candidate node and initiates a voting request to other available slave nodes in the database cluster to enable each available slave node to participate in voting; when the number of obtained votes is half of the total number of votes, an arbitration voting request is initiated to an arbitration service node independently deployed in the database cluster to enable the arbitration service node to vote based on the node state and cluster information of the original master node; when the votes of the arbitration service node are obtained, the latest GTID node is used to supplement the incremental data and is converted into a new master node, wherein the latest GTID node is the node with the largest transaction range in the database cluster. In the method, the master selection process is triggered by the slave node when the master node heartbeat times out or the database process is unavailable, and the slave node is converted into a candidate node to initiate a vote to other available slave nodes, and the nodes are elected according to the term, log state and node priority returned by each node; when the number of obtained votes is half of the total number of votes, an independently deployed arbitration service node is introduced to make a supplementary vote by reversely verifying the state of the original master node and the cluster information to break the half deadlock in the even number of nodes; after more than half of the votes are obtained, the incremental data is supplemented to the latest GTID node to complete the data consistency recovery and switch to a new master node. Thus, reliable master selection can be completed under the condition of half failure of even number of nodes, the overall availability and failure recovery capability of the database system are improved, and the technical problem that the election and master switching cannot be completed under the condition of half failure of even number of nodes is solved. BRIEF DESCRIPTION OF DRAWINGS
[0016] The drawings incorporated into the specification and constituting a part of the specification show embodiments consistent with the present application and, together with the specification, serve to explain the principles of the present application.
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows, and obviously, other drawings can be obtained by those skilled in the art without creative labor under the premise of not paying the creative labor.
[0018] One or more embodiments are exemplarily illustrated by the pictures in the drawings corresponding thereto, and these exemplary illustrations do not constitute a limitation on the embodiments, and the elements with the same reference numerals in the drawings represent similar elements, unless otherwise specified, and the drawings do not constitute a proportional limitation.
[0019] Figure 1 is a flow chart of an optional high-availability autonomous switchover method according to an embodiment of the present application; Figure 2 is an architecture diagram of an optional high-availability autonomous switchover method according to an embodiment of the present application; Figure 3 is a structural schematic diagram of an optional high-availability autonomous switchover device according to an embodiment of the present application; Figure 4 is a structural schematic diagram of an optional high-availability autonomous switchover system according to an embodiment of the present application; Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in a clear and complete manner with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0021] The following disclosure provides many different embodiments, or examples, for implementing different structures of the present application. For the purpose of simplicity and clarity, the description in the following text describes the components and settings of specific examples. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeatedly refer to the numbers and / or letters in different examples. Such repetition is for the purpose of simplification and clarity, and it does not indicate the relationship between the various embodiments and / or settings discussed.
[0022] According to a first aspect of the embodiments of the present application, a high-availability autonomous switchover method is provided, applied to any slave node in a database cluster, and optionally, as shown in Figure 1 the above method comprises: S102, when the proxy component of the target slave node times out without receiving the heartbeat packet sent by the proxy component of the original master node in the database cluster, or the received heartbeat packet indicates that the database process of the original master node is unavailable, updating the node state of the original master node as an abnormal node, wherein the target slave node is any slave node in the database cluster; S104, the target slave node converts itself into a candidate node, and initiates a voting request to other available slave nodes in the database cluster, so that each available slave node participates in voting; S106, when the number of obtained votes is half of the total number of votes, an arbitration vote request is initiated to an arbitration service node independently deployed in the database cluster, so that the arbitration service node votes based on the node state of the original master node and the cluster information; S108, when the votes of the arbitration service node are obtained, the latest GTID node is used for incremental data supplement, and the latest GTID node is converted into a new master node, wherein the latest GTID node is a node with the largest transaction range in the database cluster.
[0023] Optionally, in the embodiment, a high-availability autonomous switching method of a database cluster is provided, which is used to enable any one of the slave nodes (target slave node Follower) to automatically complete master-slave switching when the original master node is abnormal, thereby improving the high-availability capability of the even-numbered node cluster. The reliable switching of the master node is realized through the heartbeat detection, election voting, and arbitration service mechanism cooperated with the agent component (DBAgent) running in the cluster, and the architecture diagram is as shown in Figure 2 .
[0024] Firstly, the target slave node continuously monitors the heartbeat packet sent by the agent component of the original master node (Leader) through its agent component. When the target slave node does not receive the heartbeat packet of the original master node within a preset time, or the received heartbeat packet indicates that the database process of the original master node is unavailable, the target slave node updates the node state of the original master node as an abnormal node and records the abnormal reason. The update of the node state triggers the start of the master election process.
[0025] After detecting the abnormality of the original master node, the target slave node is automatically converted into a candidate node (Candidate), and broadcasts a voting request to all available slave nodes in the database cluster. The voting request contains the term number, log synchronization state, and node priority of the candidate node, and the slave nodes make a decision according to the local state after receiving the request, including comparing the term number, the degree of new and old log, and the node priority, so as to decide whether to vote for the candidate node. Each slave node can only vote once in the same term, avoiding repeated voting leading to election confusion.
[0026] When the candidate node finds that there is only half of the votes but not enough to form a majority in the even-numbered node deadlock scenario, the candidate node sends an arbitration vote request to an independently deployed arbitration service node. The arbitration service node does not store business data, but only participates in the voting judgment through the REST interface. The arbitration node makes an auxiliary decision on the master election behavior of the candidate node by querying the real-time state of the original master node in the cluster in reverse, comparing the cluster topology information, and verifying whether the number of nodes is even. When the original master node is indeed unavailable and the cluster meets the arbitration condition, the arbitration service node votes for the candidate node, so that it can break through the half limit and form an effective majority.
[0027] After the candidate node obtains more than half of the votes, it does not immediately switch to the master node, but first initiates an incremental data synchronization request to the node with the latest data in the cluster. The candidate node will pull the incremental data from the last synchronization position based on the GTID or log site, apply it to the local database, and ensure that the data is consistent with the latest node. After completing the data supplement, the candidate node formally converts to the new master node (Leader) and restores the external write service, realizing the smooth switching of the cluster and the business continuity guarantee.
[0028] Optionally, in the embodiment, the beneficial effects mainly manifest in the following four aspects: 1. Solving the election deadlock of even nodes, significantly improving system availability. By introducing an arbitration service as the "decisive vote" in key scenarios, providing additional voting support when the number of votes reaches half but cannot exceed half, effectively breaking the bottleneck of the majority of even nodes, so that the system can still complete the master selection when half of the nodes fail. This mechanism enables typical 1 master 1 backup, 1 master 3 backup deployment architecture to maintain nearly 100% availability under half failure.
[0029] 2. Avoiding single-point dependence and enhancing system fault tolerance. The arbitration service is independently deployed and does not store business data, decoupling functions and reducing system complexity; combined with heartbeat detection, periodic detection, and reverse state query, a three-way verification mechanism is formed to ensure that the judgment of the master node state is more accurate and reliable. The arbitration service only participates in the election deadlock and does not interfere with the normal RAFT process, balancing system performance and reliability.
[0030] 3. Smooth integration of existing architecture, reducing deployment and operation cost. Using standard REST interface design, it can be directly integrated with existing database cluster architecture without changing the underlying replication mechanism. The arbitration service can be deployed on a lightweight node with very low dependence on hardware resources. The three types of operation boundaries, heartbeat interface, arbitration voting interface, and reverse query interface, are clear and easy to implement and standardize. In the case of regular failure, the RAFT election process is still completely followed, ensuring consistent and predictable system behavior.
[0031] 4. Improving data consistency and election security. Based on the reverse state query, the arbitration service can accurately identify the actual state of the original master node, avoiding split-brain from the source; when multiple candidate nodes compete, the arbitration service provides an authoritative arbitration vote to avoid voting conflicts, making the master selection process more stable and controllable, thereby further improving the system's data consistency guarantee capability in complex failure environments.
[0032] As an optional example, initiating a voting request to other available slave nodes in the database cluster to enable each available slave node to participate in the voting includes: sending a voting request containing state information of the target slave node to each available slave node, so that each available slave node receiving the voting request decides voting intention according to its own state information and the state information of the target slave node, wherein the state information includes term number, log information and priority; The target slave node simultaneously receives voting requests from other candidate nodes and participates in voting, so that each node in the database cluster is both a voting initiator and a voting participant in the voting process.
[0033] Optionally, in this embodiment, the target slave node becomes a candidate node after detecting the abnormality of the original master node, and needs to initiate a voting request to other available slave nodes in the database cluster to promote the execution of the election process. Specifically, the candidate node sends a voting request carrying its own state information to each available slave node, so that each slave node receiving the voting request can make a voting decision based on its own state and the state of the candidate node. The state information includes the current term number, log synchronization position (such as GTID or log index), node priority and other key parameters, which are used to ensure that the election behavior complies with the consistency principle and security constraints of the RAFT protocol.
[0034] When processing the voting request, each slave node compares the term, the latest log progress and the preset node priority of the node with the corresponding information provided by the candidate node, and then decides whether to cast a yes vote to the candidate node. In addition, during the election process, any other slave node may also become a candidate node and initiate voting due to detection of the abnormality of the original master. Therefore, the target slave node not only needs to send a voting request to other nodes, but also needs to receive the incoming voting request and participate in voting according to the same rules. Through this two-way voting mechanism, each node in the database cluster not only assumes the role of a voting initiator, but also fulfills the duty of a voting participant in the election process, thereby ensuring that the master election process of the entire cluster can reliably run in a decentralized and distributed environment.
[0035] As an optional example, sending a voting request containing state information of the target slave node to each available slave node, so that each available slave node receiving the voting request decides voting intention according to its own state information and the state information of the target slave node includes: Each available slave node receiving the voting request compares its own state information with the state information of the target slave node, and casts a yes vote if the term number of the target slave node is greater than its own term number or the priority of the target slave node is higher than its own priority, and casts a no vote if the term number of the target slave node is less than or equal to its own term number or the priority of the target slave node is lower than its own priority, and its database process is available.
[0036] Optionally, in the embodiment, a voting request containing target slave node state information is sent to each available slave node in the database cluster, so as to enable the slave node receiving the voting request to make a voting decision based on unified indicators. The state information includes term number, log information, and priority, and other key parameters for measuring node stability and reliability. After receiving the voting request, each slave node first compares its own state information with the state information of the target slave node, and determines its voting intention according to a preset decision rule. When the term number of the target slave node is greater than its own term number, or the priority of the target slave node is higher than its own priority, the slave node determines that the target slave node has higher reliability in consistency and service capability, and thus votes for the target slave node. When the term number of the target slave node is less than or equal to its own term number, or the priority of the target slave node is lower than its own priority, and the database process of the slave node is in an available state, the slave node will vote against. Through the above comparison and evaluation mechanism, autonomous voting between nodes based on multiple state dimensions is realized, thereby constructing a more stable, objective, and expandable master node election process.
[0037] As an optional example, when the number of obtained votes is half of the total number of votes, an arbitration voting request is initiated to an arbitration service node independently deployed in the database cluster, so that the arbitration service node votes based on the node state of the original master node and the cluster information, including: The arbitration service node is initiated to an arbitration voting request, so that the arbitration service node calls a database detection command to confirm the node state of the original master node according to the cluster node list and the current cluster configuration information provided by the target slave node, and votes against when the original master node is in a normal operating state, and votes for when the original master node is abnormal or unreachable.
[0038] Optionally, in this embodiment, in the voting process initiated by the target slave node, if it fails to obtain more than half of the votes from other available slave nodes, it further initiates an arbitration voting request to an arbitration service node deployed independently outside the database cluster to make a supplementary ruling on the election result. Specifically, the target slave node sends the current cluster node list and cluster configuration information to the arbitration service node, so that the arbitration service node can fully understand the current cluster structure and node running state. After receiving the arbitration voting request, the arbitration service node will independently verify the running state of the original master node based on the information. If the detection result shows that the original master node is still in normal operation state and is in an accessible state, the arbitration service node will cast an opposing vote to avoid double master or unnecessary master node switching; if it is confirmed that the original master node has been abnormal, unreachable or lost the ability to serve externally, the arbitration service node will cast a vote of approval, thereby supporting the target slave node to become the new master node. By introducing an independent arbitration mechanism, the situation of vote deadlock in an even number of node cluster can be effectively avoided, and the accuracy of master-slave switching decision and the overall high availability of the cluster can be improved.
[0039] Optionally, in this embodiment, after the target slave node initiates an arbitration voting request to an independently deployed arbitration service node, and the arbitration service node completes the voting based on the node state of the original master node and the current cluster information, the system still needs to handle the possible election failure situation. Specifically, after the target slave node counts all the voting results including the arbitration service node, if the number of votes obtained finally still does not exceed the half threshold, the election process is determined to be a failure. At this time, in order to avoid long-term master node vacancy caused by the continuous competition of multiple nodes, the target slave node will automatically exit the candidate state and return to the role of an ordinary slave node, and stop the current round of election process. After returning, the target slave node re-joins the regular heartbeat detection and cluster state monitoring process, and waits for the next round of election condition to be triggered, such as detecting the failure of the original master node again or receiving a new round of election request initiated by other nodes. Through this automatic rollback and re-participation mechanism, the system can effectively avoid continuous election conflict and election storm, and ensure that the cluster still maintains stable election rhythm and controllable master node switching process in complex network or multi-node competition scenarios.
[0040] As an optional example, the incremental data supplement to the latest GTID node includes: Taking the node with the largest range of executed transactions in the database cluster as the latest GTID node; Requesting the latest GTID node to obtain incremental data since its last synchronized log position; Applying the incremental data to its own database.
[0041] Optionally, in the present embodiment, in order to ensure data consistency and improve the reliability of the fault switching, the target slave node needs to perform an incremental data supplement operation on the node with the latest data version in the database cluster during the process in which the target slave node competes to become a new master node. Specifically, first, a node with the latest data version and the most complete log in the cluster is selected as the latest GTID node; then, the target slave node initiates an incremental data pulling request to the latest GTID node according to the last log position that has been synchronized by the target slave node, and requests to obtain all incremental logs or data change records generated after the log position. After receiving the request, the latest GTID node filters the data according to the log position provided by the target slave node, and returns the corresponding incremental data segment. After receiving the incremental data, the target slave node parses and applies the incremental data to the local database instance in sequence, and makes the data state of the target slave node consistent with that of the data source node by replaying the log or performing the corresponding write operation. Through the above incremental data supplement mechanism, the target slave node can quickly complete data leveling before entering the master node role, avoid the problem of inconsistent master-slave data, and improve the data security and service continuity of the system in the fault switching scenario.
[0042] As an optional example, the arbitration service node is independently deployed in the database cluster based on a standard REST interface, does not store business data, and is only used to receive arbitration voting requests, confirm the state of the original master node, and vote on the master selection request of the candidate node.
[0043] Optionally, in the present embodiment, the arbitration service node is independently deployed using a standard REST interface and communicates with each node of the database cluster. The arbitration service node does not store any business data and does not participate in normal data read and write operations. Its main responsibility is to receive arbitration voting requests from candidate nodes, independently confirm the state of the original master node, and vote for the candidate nodes in the master selection process. Specifically, when a candidate node fails to obtain more than half of the votes in the cluster, it sends its state information, cluster node list, and current cluster configuration to the arbitration service node through the REST interface. The arbitration service node confirms whether the original master node is in a normal operating state by calling a database detection command or other monitoring means, and then casts a vote of approval or disapproval according to the verification result. Through independent deployment and standardized interface, the arbitration service node achieves loose coupling with the database cluster, avoids dependence on business data, and can provide reliable decision support in critical election scenarios, thereby significantly improving the system availability and election reliability in the case of an even number of nodes or half of the nodes failing.
[0044] It should be noted that, for the foregoing method embodiments, in order to simply describe, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily necessary for the present application.
[0045] According to another aspect of the embodiments of the present application, a device for high-availability autonomous switchover is also provided, which is applied to any slave node in a database cluster, as shown in the following. Figure 3 The device comprises: An updating module 302, configured to update a node state of an original master node as an abnormal node when a proxy component of the target slave node fails to receive a heartbeat packet sent by a proxy component of the original master node in the database cluster within a timeout period or the received heartbeat packet indicates that a database process of the original master node is unavailable, wherein the target slave node is any slave node in the database cluster. A first voting module 304, configured to convert the target slave node into a candidate node and initiate a voting request to other available slave nodes in the database cluster, so as to enable the available slave nodes to participate in voting. A second voting module 306, configured to initiate an arbitration voting request to an arbitration service node independently deployed in the database cluster when a number of favorable votes obtained is half of a total number of votes, so as to enable the arbitration service node to vote based on the node state of the original master node and cluster information. A switching module 308, configured to perform incremental data supplement to a latest GTID node and convert into a new master node when a favorable vote of the arbitration service node is obtained, wherein the latest GTID node is a node with the largest transaction range in the database cluster.
[0046] It should be noted that the updating module 302 in the embodiment can be used to execute step S102 in the embodiments of the present application, the first voting module 304 in the embodiment can be used to execute step S104 in the embodiments of the present application, the second voting module 306 in the embodiment can be used to execute step S106 in the embodiments of the present application, and the switching module 308 in the embodiment can be used to execute step S108 in the embodiments of the present application.
[0047] As an optional example, the first voting module comprises: A first voting unit, configured to send a voting request containing state information of the target slave node to each available slave node, so as to enable each available slave node receiving the voting request to decide a voting intention according to the state information of the target slave node and the state information of the available slave node, wherein the state information comprises a term number, log information and a priority. The second voting unit is configured to receive a voting request from each of the other candidate nodes and participate in the voting, so that each node in the database cluster is both a voting initiator and a voting participant in the voting process.
[0048] As an optional example, the first voting unit comprises: The voting sub-unit is configured to compare the state information of each available slave node with the state information of the target slave node, and vote in favor if the term number of the target slave node is greater than the term number of the available slave node, or the priority of the target slave node is higher than the priority of the available slave node; vote against if the term number of the target slave node is less than or equal to the term number of the available slave node, or the priority of the target slave node is lower than the priority of the available slave node, and the database process of the available slave node is available.
[0049] As an optional example, the second voting module comprises: The third voting unit is configured to initiate an arbitration voting request to the arbitration service node, so that the arbitration service node confirms the node state of the original master node according to the cluster node list and the current cluster configuration information provided by the target slave node, and votes against if the original master node is confirmed to be in a normal operating state, and votes in favor if the original master node is confirmed to be abnormal or unreachable.
[0050] As an optional example, the switching module comprises: The determination unit is configured to determine the node with the largest transaction range in the database cluster as the latest GTID node; The acquisition unit is configured to request the latest GTID node to acquire the incremental data since the last synchronized log position of the latest GTID node; The application unit is configured to apply the incremental data to the database of the latest GTID node.
[0051] As an optional example, the arbitration service node is independently deployed in the database cluster based on a standard REST interface, does not store business data, and is only used to receive arbitration voting requests, confirm the state of the original master node, and vote on the master election request of the candidate node. Other examples of the embodiment are described above, and will not be repeated here.
[0052] According to a third aspect of the embodiments of the present application, the present application provides a high-availability autonomous switching system applied to a database cluster, which can be optionally as shown in Figure 4 The original master node 402 and its proxy component 404, a plurality of slave nodes 406 and their proxy components 408, and an arbitration service node 410 independently deployed in the database cluster. The proxy component 404 of the original master node 402 is configured to periodically send a heartbeat packet to the proxy component 408 of each slave node 406 in the database cluster; The proxy component 408 of the target slave node 406 is configured to receive the heartbeat packet sent by the proxy component 404 of the original master node 402, and the target slave node 406 is configured to update the node state of the original master node 402 as an abnormal node when the proxy component 408 of the target slave node 406 times out without receiving the heartbeat packet or the received heartbeat packet indicates that the database process of the original master node 402 is unavailable, wherein the target slave node 406 is any one of the plurality of slave nodes 406; The target slave node 406 is further configured to convert itself into a candidate node, and initiate a voting request to other available slave nodes so as to enable the available slave nodes to participate in voting. The target slave node 406 is further configured to initiate an arbitration voting request to the arbitration service node 410 when the number of obtained votes is half of the total number of votes. The arbitration service node 410 is configured to receive the arbitration voting request initiated by the target slave node 406, and vote based on the node state of the original master node 402 and the cluster information. The target slave node 406 is further configured to, when obtaining the votes of the arbitration service node 410, perform incremental data supplement to the latest GTID node and convert itself into a new master node, wherein the latest GTID node is a node in the database cluster that has executed the largest range of transactions.
[0053] Other examples of the embodiment can refer to the examples described above, and will not be described herein.
[0054] Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present application, as shown in Figure 5 The electronic device includes a processor 502, a communication interface 504, a memory 506, and a communication bus 508, wherein the processor 502, the communication interface 504, and the memory 506 complete communication with each other through the communication bus 508, wherein The memory 506 is configured to store a computer program. The processor 502 is configured to execute the computer program stored in the memory 506, and implement the following steps: When the proxy component of the target slave node times out without receiving the heartbeat packet sent by the proxy component of the original master node in the database cluster or the received heartbeat packet indicates that the database process of the original master node is unavailable, the node state of the original master node is updated as an abnormal node, wherein the target slave node is any one of the slave nodes in the database cluster. The target slave node converts itself into a candidate node, and initiates a voting request to other available slave nodes in the database cluster so as to enable the available slave nodes to participate in voting. When the number of votes obtained is half of the total number of votes, an arbitration vote request is initiated to an arbitration service node independently deployed in the database cluster, so that the arbitration service node votes based on the node state of the original master node and the cluster information; When the votes of the arbitration service node are obtained, the latest GTID node is used to supplement the incremental data, and the latest GTID node is converted into a new master node, wherein the latest GTID node is the node with the largest transaction range in the database cluster.
[0055] Optionally, in the embodiment, the communication bus can be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The communication bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 5 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. The communication interface is used for communication between the electronic device and other devices.
[0056] The memory can include a RAM and can also include a non-volatile memory, for example, at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0057] As an example, the memory 506 can include, but is not limited to, the update module 302, the first voting module 304, the second voting module 306, and the switching module 308 in the high-availability autonomous switching device. In addition, other module units in the high-availability autonomous switching device can also be included, but not limited to, which will not be described in detail in this example.
[0058] The processor can be a general-purpose processor, which can include, but is not limited to, a CPU (Central Processing Unit), an NP (Network Processor), and the like; and can also be a DSP (Digital Signal Processing), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component.
[0059] Optionally, the specific examples in the embodiments can refer to the examples described in the above embodiments, and the embodiments will not be described here again.
[0060] Those skilled in the art can understand that, Figure 5 The structure shown is only schematic, and the device implementing the method of high-availability autonomous switching can be a terminal device, which can be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, a Mobile Internet Device (MID), a PAD, or the like. Figure 5 The structure of the electronic device is not limited. For example, the electronic device can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figure, or have a different configuration from that shown in the figure. Figure 5 The structure of the electronic device is not limited. For example, the electronic device can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figure, or have a different configuration from that shown in the figure. Figure 5 The structure of the electronic device is not limited. For example, the electronic device can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figure, or have a different configuration from that shown in the figure.
[0061] Those skilled in the art can understand that all or part of the steps of the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device by a program, and the program can be stored in a computer readable storage medium, which can include a flash disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
[0062] According to another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which stores a computer program, and when the computer program is run by a processor, the steps of the above method of high-availability autonomous switching are executed.
[0063] Optionally, in the embodiments, those skilled in the art can understand that all or part of the steps of the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device by a program, and the program can be stored in a computer readable storage medium, which can include a flash disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
[0064] The serial numbers of the above embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.
[0065] The integrated units in the above embodiments, if implemented in the form of software function units and sold or used as independent products, can be stored in the above computer-readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions to make one or more computer devices (which can be personal computers, servers or network devices, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
[0066] In the above embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0067] In the several embodiments provided by the present application, it should be understood that the disclosed client can be implemented in other ways. Of course, the above device embodiment is only illustrative, and for example, the division of the units is only a logical function division, and there can be another division manner in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, unit or module, and can be electrical or other forms.
[0068] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., they can be located in one place or distributed on multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiment according to actual needs.
[0069] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0070] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.
Claims
1. A method for high-availability autonomous switching, characterized in that, Applied to any slave node in a database cluster, including: If the proxy component of the target slave node does not receive a heartbeat packet from the proxy component of the original master node in the database cluster within a timeout period, or if the received heartbeat packet indicates that the database process of the original master node is unavailable, the node status of the original master node is updated to an abnormal node, wherein the target slave node is any slave node in the database cluster. The target slave node transforms itself into a candidate node and initiates a voting request to other available slave nodes in the database cluster, so that each available slave node can participate in the voting. When the number of affirmative votes obtained is half of the total number of votes, an arbitration vote request is initiated to the arbitration service node independently deployed in the database cluster, so that the arbitration service node votes based on the node status and cluster information of the original master node. Upon receiving a vote of approval from the arbitration service node, incremental data is added to the latest GTID node, and the node is converted into a new master node. The latest GTID node is the node with the largest range of executed transactions in the database cluster.
2. The method according to claim 1, characterized in that, Initiating voting requests to other available slave nodes in the database cluster to enable each available slave node to participate in the voting includes: A voting request containing the status information of the target slave node is sent to each available slave node, so that each available slave node that receives the voting request can decide its voting intention based on its own status information and the status information of the target slave node. The status information includes term number, log information and priority. The target node simultaneously receives voting requests from other candidate nodes and participates in the voting process, so that each node in the database cluster is both a voting initiator and a voting participant.
3. The method according to claim 2, characterized in that, Sending a voting request containing the state information of the target slave node to each available slave node, so that each available slave node receiving the voting request can determine its voting intention based on its own state information and the state information of the target slave node, includes: Each available slave node that receives the voting request compares its own status information with the status information of the target slave node. If the term number of the target slave node is greater than its own term number, or the priority of the target slave node is higher than its own priority, it votes in favor. If the term number of the target slave node is less than or equal to its own term number, or the priority of the target slave node is lower than its own priority, and its own database process is available, it votes against.
4. The method according to claim 1, characterized in that, When the number of affirmative votes obtained is half of the total number of votes, an arbitration vote request is initiated to the arbitration service node independently deployed in the database cluster, so that the arbitration service node votes based on the node status and cluster information of the original master node, including: An arbitration vote request is initiated to the arbitration service node, so that the arbitration service node, based on the cluster node list provided by the target slave node and the current cluster configuration information, calls a database probe command to confirm the node status of the original master node. If the original master node is confirmed to be in normal operation, the arbitration service node votes against it; if the original master node is confirmed to be abnormal or unreachable, the arbitration service node votes in favor.
5. The method according to claim 1, characterized in that, Incremental data supplementation to the latest GTID node includes: The node with the largest range of executed transactions in the database cluster is designated as the latest GTID node. Request the latest GTID node to obtain incremental data since its last synchronized log position; The incremental data is then applied to its own database.
6. The method according to claim 1, characterized in that, The arbitration service node is independently deployed in the database cluster based on a standard REST interface. It does not store business data and is only used to receive arbitration voting requests, confirm the status of the original master node, and vote on the election requests of candidate nodes.
7. A highly available autonomous failover system, characterized in that, This is applied to a database cluster, including the original master node and its proxy components, multiple slave nodes and their proxy components, and an arbitration service node independently deployed in the database cluster. The proxy component of the original master node is used to periodically send heartbeat packets to the proxy component of each slave node in the database cluster. The proxy component of the target slave node is used to receive the heartbeat packet sent by the proxy component of the original master node. The target slave node is used to update the node status of the original master node to an abnormal node when the proxy component of the target slave node fails to receive the heartbeat packet within a timeout period, or when the received heartbeat packet indicates that the database process of the original master node is unavailable. The target slave node is any one of a plurality of slave nodes. The target slave node is also used to convert itself into a candidate node and initiate a voting request to other available slave nodes so that each available slave node can participate in the voting. The target slave node is also used to initiate an arbitration vote request to the arbitration service node when the number of affirmative votes obtained is half of the total number of votes; The arbitration service node is used to receive the arbitration voting request initiated by the target slave node, and to vote based on the node status and cluster information of the original master node. The target slave node is also used to supplement incremental data to the latest GTID node and become a new master node when it receives the approval vote of the arbitration service node, wherein the latest GTID node is the node with the largest range of executed transactions in the database cluster.
8. A highly available autonomous switching device, characterized in that, Applied to any slave node in a database cluster, including: The update module is used to update the node status of the original master node to an abnormal node when the proxy component of the target slave node fails to receive a heartbeat packet from the proxy component of the original master node in the database cluster within a timeout period, or when the received heartbeat packet indicates that the database process of the original master node is unavailable. The target slave node is any slave node in the database cluster. The first voting module is used to convert the target slave node into a candidate node and initiate a voting request to other available slave nodes in the database cluster so that each available slave node can participate in the voting. The second voting module is used to initiate an arbitration voting request to the arbitration service node independently deployed in the database cluster when the number of affirmative votes obtained is half of the total number of votes, so that the arbitration service node can vote based on the node status and cluster information of the original master node. The switching module is used to supplement incremental data to the latest GTID node and convert it into a new master node when it receives the approval vote of the arbitration service node. The latest GTID node is the node with the largest range of executed transactions in the database cluster.
9. A computer-readable storage medium storing a computer program, characterized in that, The computer program is executed by the processor to perform the method described in any one of claims 1 to 6.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method described in any one of claims 1 to 6 through the computer program.