Database cluster master node determination method, device, electronic device and storage medium

By setting up the master node information storage area in the shared storage space of the database cluster, obtaining and determining the master node status, and performing cluster node voting processing when it fails, the data chaos caused by multiple master nodes is solved, and the high availability and stability of the database cluster is achieved.

CN119402333BActive Publication Date: 2025-08-22本原数据(北京)信息技术有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411311779.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-20
Publication Date
2025-08-22
Estimated Expiration
2044-09-20

AI Technical Summary

Technical Problem

In a database cluster, multiple master nodes may occur when the master node fails, resulting in confusion in data writing.

Method used

By setting up a primary node information storage area in the shared storage space, obtaining the primary node information, determining the primary node status, and performing cluster node voting processing when the primary node fails, selecting the only target primary node.

Benefits of technology

Ensure that there are only one master nodes in the database cluster, avoid data writing confusion, and improve the high availability and stability of the database system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119402333B_ABST
    Figure CN119402333B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a method, device, electronic device and storage medium for determining the master node of a database cluster, which belongs to the field of database management technology. The method includes: a master node information storage area is provided in the shared storage space, and the master node information storage area is used to store the master node information of the cluster master node. The method includes: obtaining the master node information through the master node information storage area; determining the master node status of the cluster master node based on the master node information; in response to the master node status being a failed state, performing cluster node voting processing on each of the cluster standby nodes to obtain corresponding node voting information; and determining the target master node from a plurality of the database nodes based on the node voting information. The embodiments of the present application can avoid the occurrence of multiple master nodes in a database cluster and determine a unique master node.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database management technology, and in particular to a method, device, electronic device, and storage medium for determining a master node of a database cluster. Background Art

[0002] In related art, a shared storage database cluster refers to a group of database servers that share a shared storage space, so that each node in the cluster can access the same database files.

[0003] Database clusters typically use a master-slave model, where the master node handles all data write and update requests, while the slave node handles data query and read requests. If a master node in a cluster fails, the slave node becomes the master node and continues to provide normal data read and write services to upper-layer applications, ensuring high availability of the database cluster.

[0004] However, in some cases, when a master node fails, all backup nodes may become master nodes within the same period of time, resulting in multiple master nodes in the cluster and causing data write confusion. Therefore, determining the master node of a database cluster has become a pressing technical issue. Summary of the Invention

[0005] The main purpose of the embodiments of the present application is to propose a method, device, electronic device and storage medium for determining the master node of a database cluster, aiming to avoid the occurrence of multiple master nodes in the database cluster and determine a unique master node.

[0006] To achieve the above objectives, a first aspect of an embodiment of the present application proposes a method for determining a master node of a database cluster, which is applied to a database cluster. The database cluster includes multiple database nodes, one of which is a cluster master node and the rest are cluster standby nodes. The database clusters together constitute a shared storage space. A master node information storage area is provided in the shared storage space. The master node information storage area is used to store master node information of the cluster master node. The method includes:

[0007] Obtaining the master node information through the master node information storage area;

[0008] Determine the master node status of the cluster master node based on the master node information;

[0009] In response to the master node being in a failed state, performing cluster node voting on each of the cluster standby nodes to obtain corresponding node voting information;

[0010] A target master node is determined from the plurality of database nodes according to the node voting information.

[0011] In some embodiments, the master node information includes master node identity information, and determining the master node status of the cluster master node based on the master node information includes:

[0012] Querying the cluster master node from the plurality of database nodes according to the master node identity information to obtain master node query information;

[0013] The master node status is determined based on the master node query information.

[0014] In some embodiments, the master node information further includes operation time data, and determining the master node status of the cluster master node based on the master node information includes:

[0015] Based on the operation time data and the preset data update threshold time, the update operation of the cluster master node is detected at time intervals to determine the master node status; wherein, the operation time data is used to record the timestamp when the cluster master node performs the data update operation.

[0016] In some embodiments, each database node is provided with a voting information storage area, and performing cluster node voting processing on each cluster standby node to obtain corresponding node voting information includes:

[0017] Each of the cluster standby nodes generates a node voting value in the corresponding voting information storage area based on its own standby node identity information;

[0018] Each of the cluster standby nodes compares voting values ​​according to the corresponding node voting values ​​to obtain a maximum voting value, and determines a first extreme standby node corresponding to the maximum voting value;

[0019] Obtaining a preset second extreme value standby node, wherein the second extreme value standby node is obtained by the maximum voting value in the last cluster node voting process;

[0020] The node voting information of each of the cluster standby nodes is obtained by performing a voting value comparison based on the node voting value of the first extreme value standby node and the node voting value of the second extreme value standby node.

[0021] In some embodiments, the voting information storage area further includes voting version information. Before each of the cluster standby nodes compares voting values ​​according to the corresponding node voting values ​​to obtain a maximum voting value and determines a first extreme standby node corresponding to the maximum voting value, the process further includes:

[0022] Based on the voting version information of each of the cluster standby nodes, perform latest node screening on the cluster standby nodes to obtain the latest version nodes;

[0023] Each of the cluster standby nodes compares voting values ​​according to the corresponding node voting values ​​to obtain a maximum voting value, and determines a first extreme standby node corresponding to the maximum voting value, including:

[0024] The voting values ​​are compared based on the node voting values ​​corresponding to the latest version node to obtain a maximum voting value, and a first extreme value standby node corresponding to the maximum voting value is determined.

[0025] In some embodiments, the master node information includes operation time data, the master node information storage area also includes master node version information, and determining the target master node from the plurality of database nodes based on the node voting information includes:

[0026] Obtain the operation time data through the master node information storage area to obtain the latest time data;

[0027] Obtaining a master node activity status of the cluster master node based on the master node version information and time comparison information between the latest time data and the previous operation time data;

[0028] A target master node is determined based on the master node activity status and the node voting information.

[0029] In some embodiments, when a network partition failure occurs in the database cluster, the database cluster includes a multi-node partition and a small number of node partitions, and the method further includes:

[0030] Determine the master node partition information of the cluster master node according to the master node information;

[0031] When the master node partition information indicates that the cluster master node is in the few-node partition, the cluster master node is converted into the cluster standby node, and data in the master node information storage area is cleared;

[0032] By performing cluster node voting processing on each of the cluster standby nodes in the multi-node partition, corresponding node voting information is obtained, and a target master node is determined from the database nodes in the multi-node partition according to the node voting information.

[0033] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a device for determining a master node of a database cluster, the device comprising:

[0034] An information acquisition module, configured to acquire the master node information through the master node information storage area;

[0035] A status determination module, configured to determine the master node status of the cluster master node based on the master node information;

[0036] a node voting module, configured to, in response to the master node being in a failed state, perform cluster node voting on each of the cluster standby nodes to obtain corresponding node voting information;

[0037] A master node determination module is used to determine a target master node from the multiple database nodes according to the node voting information.

[0038] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements the method for determining the master node of the database cluster described in the first aspect above.

[0039] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the method for determining the master node of the database cluster described in the first aspect above.

[0040] The database cluster master node determination method, device, electronic device and storage medium proposed in the present application are provided with a master node information storage area in the shared storage space jointly constituted by the database cluster, which is used to store the master node information of the cluster master node. The master node information is obtained through the master node information storage area, and the master node status of the cluster master node is determined based on the master node information. In response to the master node status being a failed state, a cluster node voting process is performed on each cluster standby node to obtain the corresponding node voting information. Then, the target master node is determined from multiple database nodes based on the node voting information. It can be seen from this that the present application sets a master node information storage area specifically for recording master node information in the shared storage space. After the target master node is determined, the corresponding master node information is stored in the master node information storage area, thereby determining the unique master node of the database cluster. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 This is a flowchart of a method for determining a master node of a database cluster provided by an embodiment of the present application;

[0042] Figure 2 yes Figure 1 Flowchart of step S102 in FIG.

[0043] Figure 3 yes Figure 1 Flowchart of step S103 in FIG.

[0044] Figure 4 yes Figure 3 Flowchart before step S302 and step S302;

[0045] Figure 5 yes Figure 1 Flowchart of step S104 in FIG.

[0046] Figure 6 This is another flow chart of the method for determining the master node of a database cluster provided in an embodiment of the present application;

[0047] Figure 7 This is a schematic diagram of the structure of a database cluster master node determination device provided in an embodiment of the present application;

[0048] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0050] It should be noted that although the device schematics illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the device or the sequence in the flowcharts. The terms "first," "second," and so on, in the specification, claims, and drawings, are used to distinguish similar items and are not necessarily used to describe a specific sequence or precedence.

[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0052] Traditional databases typically integrate data computing and storage within a single physical node. If the database is deployed as a cluster, all nodes in the cluster will store their own copy of the data, leading to duplicate data storage and wasted storage space. To address this issue, shared storage database clusters have been developed. This architecture allows multiple database nodes to share a single shared storage space, enabling every node in the cluster to access the same database files. This reduces storage expansion costs and improves database system availability.

[0053] Database clusters typically use a master-slave model, where the master node handles all data write and update requests, while the slave node handles data query and read requests. If a master node in a cluster fails, the slave node becomes the master node and continues to provide normal data read and write services to upper-layer applications, ensuring high availability of the database cluster.

[0054] However, in some cases, when a master node fails, all backup nodes may become master nodes within the same period of time, resulting in multiple master nodes in the cluster and causing data write confusion. Therefore, determining the master node of a database cluster has become a pressing technical issue.

[0055] Based on this, the embodiments of the present application provide a method, device, electronic device and storage medium for determining the master node of a database cluster, aiming to avoid the occurrence of multiple master nodes in the database cluster and determine a unique master node.

[0056] The database cluster master node determination method, device, electronic device and storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the database cluster master node determination method in the embodiments of the present application is described.

[0057] The method for determining the master node of a database cluster provided in the embodiment of the present application relates to the field of database management technology. The method for determining the master node of a database cluster provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, or can be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the method for determining the master node of a database cluster, etc., but is not limited to the above forms.

[0058] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and the like. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments in which tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.

[0059] Figure 1 This is an optional flowchart of the method for determining the master node of a database cluster provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S104.

[0060] Step S101, obtaining master node information through the master node information storage area;

[0061] Step S102, determining the master node status of the cluster master node based on the master node information;

[0062] Step S103: In response to the master node being in a failed state, performing cluster node voting on each cluster standby node to obtain corresponding node voting information;

[0063] Step S104: determining a target master node from multiple database nodes according to the node voting information.

[0064] In steps S101 to S106 shown in the embodiment of the present application, a master node information storage area is set up in the shared storage space jointly constituted by the database cluster to store the master node information of the cluster master node. The master node information is obtained through the master node information storage area, and the master node status of the cluster master node is determined based on the master node information. In response to the master node status being a failed state, a cluster node voting process is performed on each cluster standby node to obtain corresponding node voting information. Then, the target master node is determined from multiple database nodes based on the node voting information. It can be seen that the present application sets up a master node information storage area specifically for recording master node information in the shared storage space. After the target master node is determined, the corresponding master node information is stored in the master node information storage area, thereby determining the unique master node of the database cluster.

[0065] In step S101 of some embodiments, the database cluster includes multiple database nodes, only one of which is a cluster master node, and the rest are cluster standby nodes. A master node information storage area is provided in the shared storage space of the database cluster to store master node information of the cluster master node. Thus, the master node information can be obtained through the master node information storage area. In some embodiments, the master node information storage area also stores other information about the database cluster, such as the total number of database nodes. The master node information storage area is generally sized based on the total number of database nodes and records timestamps and verification information for update operations performed by the cluster master node.

[0066] In step S102 of some embodiments, the master node status of the cluster master node is determined by acquiring the master node information, and it is judged whether the current cluster master node is still valid.

[0067] See also Figure 2 In some embodiments, the master node information includes master node identity information, and step S102 may include but is not limited to steps S201 to S202:

[0068] Step S201, querying the cluster master node from multiple database nodes based on the master node identity information to obtain master node query information;

[0069] Step S202: Determine the master node status based on the master node query information.

[0070] In step S201 of some embodiments, a cluster master node is queried from multiple database nodes based on the master node identity information to obtain master node query information. Information about the database node currently designated as the master node is obtained by querying the database cluster management service or configuration database. This information may include identity information such as the cluster master node's ID, IP address, and port number.

[0071] In step S202 of some embodiments, the cluster master node is queried to obtain master node query information, and the cluster master node's response time, heartbeat signal, error log, and other indicators are analyzed to evaluate its operating status. The cluster master node is checked to see whether it can process requests normally and whether it can maintain stable communication with other database nodes.

[0072] Through step S201 to step S202, the status of the cluster master node in the database cluster can be monitored, so that the cluster master node of the database cluster can be accurately managed.

[0073] In some embodiments, the master node information also includes operation time data, which is used to record the timestamp when the cluster master node performs a data update operation. Step S102 may include, but is not limited to, detecting the time interval between the cluster master node's update operation based on the operation time data and a preset data update threshold time to determine the master node status.

[0074] When a cluster master node performs a write operation, it leaves a specific timestamp field in the master node information storage area, representing the time of the operation. The data update threshold time is used to determine whether the cluster master node is still valid. If no update operation is performed after the data update threshold time, the cluster master node is considered to be potentially invalid. This data update threshold time can be reasonably set by those skilled in the art. This data update threshold time should be set based on the cluster's business needs and performance indicators to ensure that normal operational delays can be tolerated while potential failures can be responded to in a timely manner. If it is detected that the master node has not performed any update operations within the normal operating time range, the master node status is marked as invalid.

[0075] In step S103 of some embodiments, in response to the master node being in a failed state, cluster node voting is performed on each cluster standby node to obtain corresponding node voting information.

[0076] See also Figure 3 In some embodiments, each database node is provided with a voting information storage area, and step S103 may include but is not limited to steps S301 to S304:

[0077] Step S301: Each cluster standby node generates a node voting value in a corresponding voting information storage area based on its own standby node identity information.

[0078] Step S302: Each cluster backup node compares the voting values ​​according to the corresponding node voting values ​​to obtain the maximum voting value, and determines the first extreme backup node corresponding to the maximum voting value;

[0079] Step S303: obtaining a preset second extreme value standby node, wherein the second extreme value standby node is obtained by the maximum voting value in the last cluster node voting process;

[0080] Step S304 : comparing the node voting value of the first extreme value standby node and the node voting value of the second extreme value standby node to obtain node voting information of each cluster standby node.

[0081] In step S301 of some embodiments, each standby cluster node generates a node voting value based on its own information. The node voting value will be used in the subsequent comparison and election process. Each standby cluster node uses its own standby node identity information (such as node ID, historical voting records, etc.) to generate a unique node voting value. There are many ways to generate node voting values, such as a disk-based consensus algorithm to generate unique node voting values.

[0082] In some embodiments, the rule for generating the node voting value is: if no valid information is stored in the master node information storage area, the node voting value can be generated based on the standby node identity information of the cluster standby node.

[0083] In some embodiments, cluster node voting processing will not only occur once, so when cluster node voting processing is performed for the second time, the node voting value can be generated based on the result of the previous cluster node voting processing. If some valid information is stored in the master node information storage area, such as the total number of database nodes, or the node voting value left by the cluster master node when it previously participated in the cluster node voting process, the node voting value of each cluster standby node can be generated based on the total number of database nodes, the standby node identity information of the cluster standby node, and the node voting value recorded in the master node information storage area. The specific calculation method can be shown in the following formula (1):

[0084] Result=max-(max%nums)+nums+host_id (1)

[0085] Result represents the node voting value of each cluster standby node, max represents the node voting value recorded in the master node information storage area, nums represents the total number of database nodes, and host_id represents the standby node identity information of each cluster standby node.

[0086] In step S302 of some embodiments, each cluster standby node generates a node voting value based on its own standby node identity information, compares the node voting values ​​with those of other cluster standby nodes, and determines the cluster standby node with the largest voting value. This cluster standby node is determined as the first extreme standby node.

[0087] This process involves the cluster standby node writing and reading the node voting value. Since each database node is equipped with a voting information storage area, each cluster standby node can write the node voting value in its own voting information storage area and read the node voting values ​​of other cluster standby nodes. Therefore, there will be no simultaneous writing in the shared storage space, thereby avoiding concurrency in the shared storage space and incomplete writing of data.

[0088] In step S303 of some embodiments, a preset second extreme standby node is obtained, wherein the second extreme standby node is obtained by the maximum voting value in the last cluster node voting process. However, it should be noted that when the database cluster is initialized, there is no valid data about the database cluster in the shared storage space, and there is no valid information of the cluster master node in the master node information storage area. Therefore, the initial cluster node voting process will be performed, and at this time, the second extreme standby node cannot be obtained. Therefore, in step S304, only the node voting value of the first extreme standby node is valid, and the node voting value of the second extreme standby node is invalid, so the node voting information can also be determined.

[0089] In other cases, after the database cluster is initialized, that is, after the initial cluster node voting process is completed, the cluster master node can be obtained. However, due to some failure or network problems, the cluster master node is invalid or lost, and the cluster node voting process is repeated again to determine the new target master node. At this time, a valid second-extreme backup node can be obtained, and the corresponding valid node voting value can also be obtained.

[0090] In some embodiments, the selected first extreme backup node will be marked in the corresponding voting information storage area as an extreme node mark, and the corresponding node voting value will be stored. This allows for better identification of the second extreme backup node during subsequent cluster node voting. If this is not the initial cluster node voting process, it is possible to detect whether the corresponding extreme node mark exists in other cluster backup nodes and obtain the corresponding node voting value.

[0091] In step S304 of some embodiments, node voting information for determining a target master node is obtained based on a comparison of the node voting value of the first extreme standby node with the node voting value of the second extreme standby node. The target master node represents a database node that is about to become the cluster master node.

[0092] Through steps S301 to S304, by setting up a dedicated voting information storage area in each database node, each database node is used for voting and election. This ensures that when the master node fails, a new master node is elected through a fair, transparent, and efficient process, thereby ensuring the high availability and stability of the database cluster. On the other hand, because during cluster node voting, database nodes generate and write node voting values ​​in their own dedicated voting information storage areas, no data is written to the shared storage space. Throughout the entire process, writing to the shared storage space will not generate concurrency, avoiding the possibility of incomplete data.

[0093] See also Figure 4 In some embodiments, the voting information storage area also includes voting version information. Before step S302, the steps may include but are not limited to step S401:

[0094] Step S401: Based on the voting version information of each cluster standby node, the latest node screening process is performed on the cluster standby node to obtain the latest version node;

[0095] Step S302 may include but is not limited to step S402:

[0096] Step S402 : comparing voting values ​​based on the node voting values ​​corresponding to the latest version node to obtain a maximum voting value, and determining a first extreme backup node corresponding to the maximum voting value.

[0097] In step S401 of some embodiments, each standby cluster node records its own voting version information in a voting information storage area. The voting version information is typically an incrementing number that increases each time the node's vote value is updated. This allows synchronization and comparison of the voting version information of each standby cluster node. Storing the voting version information in the voting information storage area ensures that all standby cluster nodes can access the voting version information of other standby cluster nodes for comparison.

[0098] By filtering all standby nodes for the latest nodes, the latest version of the node is obtained. It should be noted that due to partitions in the database cluster or network latency issues, multiple node voting values ​​may be updated in a short period of time. To prevent node voting values ​​processed by different cluster nodes from being read due to network latency when each standby node performs cluster node voting, it is necessary to synchronize node voting values ​​using voting version information.

[0099] In step S402 of some embodiments, when the voting version information indicates that the node voting values ​​of the corresponding cluster standby nodes are all the latest, the voting values ​​are compared based on the node voting values ​​of the latest version nodes to obtain the maximum voting value, and the corresponding first extreme value standby node is determined.

[0100] By introducing voting version information from steps S401 to S402, the election process among cluster backup nodes can be more effectively managed, ensuring that the selected first-place backup node not only has the highest node vote value but also has the most up-to-date voting information. This increases the reliability and accuracy of the election process, helping to maintain the stability and high availability of the database cluster.

[0101] It should be noted that the weight of the voting version information is greater than the node voting value. It is necessary to first compare the voting version information to determine the latest version node, and then compare the node voting values ​​of these latest version nodes. Similarly, in step S304, the first extreme value standby node and the second extreme value standby node may have different voting version information due to external factors such as network failure. It is okay for the voting version information of the second extreme value standby node to be lower than the voting version information of the first extreme value standby node, but if there are multiple first extreme value standby nodes, it is necessary to keep the latest first extreme value standby node based on the voting version information, and then compare the voting value with the second extreme value standby node.

[0102] In step S104 of some embodiments, a target master node is determined from multiple database nodes based on the obtained node voting information.

[0103] See also Figure 5 In some embodiments, the master node information storage area further includes master node version information. Step S104 may include but is not limited to steps S501 to S503:

[0104] Step S501, obtain operation time data through the master node information storage area to obtain the latest time data;

[0105] Step S502: obtaining the master node activity status of the cluster master node based on the master node version information and the time comparison information between the latest time data and the previous operation time data;

[0106] Step S503: Determine the target master node based on the master node activity status and node voting information.

[0107] In steps S501 to S503 of some embodiments, the operation time data is obtained again through the master node information storage area to obtain the latest time data. The latest time data read is compared with the operation time data read previously to obtain the master node activity status of the cluster master node. The master node activity status is used to indicate the activity status of the cluster master node and reflect the survival status of the cluster master node. The target master node is determined based on the master node activity status, node voting information and master node version information. The master node version information is the voting version information of the cluster master node when performing cluster node voting processing. The operation time data retained by the cluster master node when performing an update operation will contain the master node version information.

[0108] It should be noted that by reading the operation time data and comparing it with the data update threshold time, if the data update threshold time is exceeded, the cluster master node will be judged invalid, and the cluster master node will be forcibly downgraded to a cluster backup node, and the target master node will be determined through cluster node voting.

[0109] However, due to the time delay between each database node when a network failure occurs, some database nodes may initiate different cluster node voting processes at different times, or when performing cluster node voting processes, some database nodes may not complete the previous cluster node voting processes due to network delays.

[0110] At this time, the operation time data in the master node information storage area can be read to obtain the latest time data, and the latest time data can be compared with the previously read operation time data to obtain the master node activity status of the cluster master node. If the time comparison information indicates that the two timestamps are different, it means that the database cluster has completed the cluster node voting process and determined the target master node. The cluster master node is already active, so there is no need to determine a new target master node. The database node can maintain the original cluster standby node status.

[0111] If the time comparison information indicates that the two timestamps are the same, it means that the target master node has not yet been selected and the database cluster is still in a state without a cluster master node. Therefore, it is necessary to complete the cluster node voting process through the node voting information to obtain the target master node.

[0112] But there is another possibility, that is, the target master node has been obtained, but the data update operation has not been performed, so the operation time data has not been updated. Alternatively, in some embodiments, the timestamp of the operation time data is partially intercepted through the system time, which can save a part of the storage space and is a common method used by those skilled in the art. Therefore, it may happen that the target master node has actually been determined and the data update operation has been performed, but the updated latest time data and the operation time data are very close in time, so the timestamp obtained by intercepting the system time is the same, but in fact these are different operation time data obtained by two different data update operations. In this possibility, it is necessary to use the master node version information, that is, the voting version information when performing cluster node voting processing. Through the master node version information, it is possible to obtain the master node version information whose operation time data is different from the latest time data, thereby determining that the target master node has been updated. It is no longer necessary to determine a new target master node, and the database node can maintain the original state of the cluster standby node.

[0113] Through steps S501 to S503, the master node activity status of the cluster master node is determined by obtaining the latest time data and master node version information, thereby determining whether the database cluster has already obtained the target master node. If the cluster master node is already active, it means that part of the database cluster has already obtained the target master node through cluster node voting, and there is no need to determine a new target master node. This avoids different cluster node voting processes due to network problems, establishes multiple different target master nodes, avoids repeated updates of the target master node, and achieves precise management of cluster master nodes.

[0114] See also Figure 6 In some embodiments, when a network partition occurs in a database cluster, the database cluster is divided into a multi-node partition and a small-node partition, which may include but is not limited to steps S601 to S603:

[0115] Step S601, determining the master node partition information of the cluster master node according to the master node information;

[0116] Step S602: When the master node partition information indicates that the cluster master node is in a small node partition, the cluster master node is converted into a cluster standby node, and the data in the master node information storage area is cleared;

[0117] Step S603 , performing cluster node voting on each cluster standby node in the multi-node partition to obtain corresponding node voting information, and determining a target master node from database nodes in the multi-node partition according to the node voting information.

[0118] In step S601 of some embodiments, a multi-node partition represents a partition that includes more than half of the database cluster. Master node partition information of the cluster master node is determined based on the master node information. Based on the master node identity information in the master node information, the database cluster can be queried to determine whether the cluster master node is in a multi-node partition or a small-node partition, thereby obtaining the master node partition information.

[0119] In step S602 of some embodiments, when the master node partition information indicates that the cluster master node is in a low-node partition, the cluster master node is converted to a cluster standby node, and the data in the master node information storage area is cleared. It should be noted that each time a target master node is determined, the data in the master node information storage area must be cleared to store the data content of the new cluster master node, thereby avoiding data errors and data confusion.

[0120] In step S603 of some embodiments, since the cluster master node is lost, a target master node needs to be re-determined. Cluster node voting is performed on each cluster standby node in the multi-node partition to obtain node voting information, and the target master node is determined from the database nodes in the multi-node partition.

[0121] This is because the cluster master node can better manage the database cluster and perform related data updates in a multi-node partition. Therefore, to maintain high availability of the database cluster and maintain continuity and a good experience for the database cluster service, the cluster master node is preferably in a multi-node partition. If the master node partition information indicates that the cluster master node is in a multi-node partition, there is no need to change the cluster master node.

[0122] In an embodiment of the present application, a master node information storage area is provided in the shared storage space jointly constituted by the database cluster, which is used to store the master node information of the cluster master node. The master node information is obtained through the master node information storage area, and the master node status of the cluster master node is determined based on the master node information. In response to the master node status being a failed state, a cluster node voting process is performed on each cluster standby node to obtain corresponding node voting information. Then, the target master node is determined from multiple database nodes based on the node voting information. It can be seen from this that the present application sets a master node information storage area specifically for recording master node information in the shared storage space. After the target master node is determined, the corresponding master node information is stored in the master node information storage area, thereby determining the unique master node of the database cluster.

[0123] See also Figure 7 The present application also provides a database cluster master node determination device, which can implement the above database cluster master node determination method, and the device includes:

[0124] An information acquisition module is used to obtain master node information through the master node information storage area;

[0125] A status determination module is used to determine the master node status of the cluster master node based on the master node information;

[0126] A node voting module is used to perform cluster node voting on each cluster standby node in response to the master node being in a failed state, and obtain corresponding node voting information;

[0127] The master node determination module is used to determine the target master node from multiple database nodes based on node voting information.

[0128] The specific implementation of the database cluster master node determination device is basically the same as the specific embodiment of the above-mentioned database cluster master node determination method, and will not be repeated here.

[0129] The present application also provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method for determining a master node of a database cluster. The electronic device can be any intelligent terminal, such as a tablet computer or an in-vehicle computer.

[0130] See also Figure 8 , Figure 8 The hardware structure of an electronic device according to another embodiment is shown. The electronic device includes:

[0131] The processor 801 may be implemented using a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.

[0132] The memory 802 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 802 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802, and the processor 801 calls and executes the database cluster master node determination method of the embodiments of this application;

[0133] Input / output interface 803, used to implement information input and output;

[0134] Communication interface 804, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, Wi-Fi, Bluetooth, etc.);

[0135] Bus 805 , which transmits information between various components of the device (e.g., processor 801 , memory 802 , input / output interface 803 , and communication interface 804 );

[0136] The processor 801 , the memory 802 , the input / output interface 803 and the communication interface 804 are connected to each other in communication within the device via a bus 805 .

[0137] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned method for determining the master node of the database cluster.

[0138] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0139] The database cluster master node determination method, device, electronic device and storage medium provided in the embodiments of the present application are provided with a master node information storage area in the shared storage space jointly constituted by the database cluster, which is used to store the master node information of the cluster master node. The master node information is obtained through the master node information storage area, and the master node status of the cluster master node is determined based on the master node information. In response to the master node status being a failed state, cluster node voting processing is performed on each cluster standby node to obtain corresponding node voting information. Then, the target master node is determined from multiple database nodes based on the node voting information. It can be seen from this that the present application sets a master node information storage area specifically for recording master node information in the shared storage space. After the target master node is determined, the corresponding master node information is stored in the master node information storage area, thereby determining the unique master node of the database cluster.

[0140] The embodiments described in the embodiments of this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.

[0141] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0142] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.

[0143] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations thereof.

[0144] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0145] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0146] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0147] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0148] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0149] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store programs.

[0150] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope of the present invention.

Claims

1. A method for determining a master node of a database cluster, applied to a database cluster, wherein the database cluster comprises a plurality of database nodes, one of which is a master node of the cluster and the rest are backup nodes of the cluster, and the database clusters together constitute a shared storage space, characterized in that: The shared storage space is provided with a master node information storage area, the master node information storage area is used to store the master node information of the cluster master node, each of the database nodes is provided with a voting information storage area, and the method includes: Obtaining the master node information through the master node information storage area; Determine the master node status of the cluster master node based on the master node information; In response to the master node being in a failed state, cluster node voting processing is performed on each of the cluster standby nodes to obtain corresponding node voting information, including: each of the cluster standby nodes generates a node voting value in the corresponding voting information storage area based on its own standby node identity information; each of the cluster standby nodes compares voting values ​​according to the corresponding node voting values ​​to obtain a maximum voting value, and determines a first extreme value standby node corresponding to the maximum voting value; obtains a preset second extreme value standby node, wherein the second extreme value standby node is obtained by the maximum voting value in the last cluster node voting processing; compares voting values ​​based on the node voting value of the first extreme value standby node and the node voting value of the second extreme value standby node, and obtains the node voting information for determining the target master node according to the comparison result; Before each of the cluster standby nodes compares the voting values ​​according to the corresponding node voting values ​​to obtain the maximum voting value and determines the first extreme standby node corresponding to the maximum voting value, the method further includes: performing latest node screening processing on the cluster standby nodes based on the voting version information of each cluster standby node to obtain the latest version node; Each of the cluster standby nodes performs a voting value comparison based on the corresponding node voting value to obtain a maximum voting value, and determines a first extreme standby node corresponding to the maximum voting value, including: performing a voting value comparison based on the node voting value corresponding to the latest version node to obtain a maximum voting value, and determining a first extreme standby node corresponding to the maximum voting value; A target master node is determined from the plurality of database nodes according to the node voting information.

2. The method according to claim 1, characterized in that The master node information includes master node identity information, and determining the master node status of the cluster master node based on the master node information includes: Querying the cluster master node from the plurality of database nodes according to the master node identity information to obtain master node query information; The master node status is determined based on the master node query information.

3. The method according to claim 1, characterized in that The master node information further includes operation time data, and determining the master node status of the cluster master node based on the master node information includes: Based on the operation time data and the preset data update threshold time, the update operation of the cluster master node is detected at time intervals to determine the master node status; wherein, the operation time data is used to record the timestamp when the cluster master node performs the data update operation.

4. The method according to claim 1, wherein The master node information includes operation time data, the master node information storage area also includes master node version information, and determining a target master node from the plurality of database nodes according to the node voting information includes: Obtain the operation time data through the master node information storage area to obtain the latest time data; Obtaining a master node activity status of the cluster master node based on the master node version information and time comparison information between the latest time data and the previous operation time data; A target master node is determined based on the master node activity status and the node voting information.

5. The method according to claim 1, characterized in that When a network partition failure occurs in the database cluster, the database cluster includes a multi-node partition and a small number of node partitions, and the method further includes: Determine the master node partition information of the cluster master node according to the master node information; When the master node partition information indicates that the cluster master node is in the few-node partition, the cluster master node is converted into the cluster standby node, and data in the master node information storage area is cleared; By performing cluster node voting processing on each of the cluster standby nodes in the multi-node partition, corresponding node voting information is obtained, and a target master node is determined from the database nodes in the multi-node partition according to the node voting information.

6. A database cluster master node determination device, characterized in that: Applied to a database cluster, the database cluster includes multiple database nodes, one of which is a cluster master node and the rest are cluster standby nodes. The database clusters together constitute a shared storage space. The device is characterized in that a master node information storage area is provided in the shared storage space, the master node information storage area is used to store the master node information of the cluster master node, and each of the database nodes is provided with a voting information storage area. The device includes: An information acquisition module, configured to acquire the master node information through the master node information storage area; A status determination module, configured to determine the master node status of the cluster master node based on the master node information; A node voting module, configured to perform cluster node voting processing on each of the cluster standby nodes in response to the master node being in a failed state, and obtain corresponding node voting information, including: each of the cluster standby nodes generating a node voting value in the corresponding voting information storage area based on its own standby node identity information; each of the cluster standby nodes performing voting value comparison based on the corresponding node voting value to obtain a maximum voting value, and determining a first extreme value standby node corresponding to the maximum voting value; obtaining a preset second extreme value standby node, wherein the second extreme value standby node is obtained by the maximum voting value in the last cluster node voting processing; performing voting value comparison based on the node voting value of the first extreme value standby node and the node voting value of the second extreme value standby node, and obtaining the node voting information for determining the target master node according to the comparison result; Before each of the cluster standby nodes compares the voting values ​​according to the corresponding node voting values ​​to obtain the maximum voting value and determines the first extreme standby node corresponding to the maximum voting value, the method further includes: performing latest node screening processing on the cluster standby nodes based on the voting version information of each cluster standby node to obtain the latest version node; Each of the cluster standby nodes performs a voting value comparison based on the corresponding node voting value to obtain a maximum voting value, and determines a first extreme standby node corresponding to the maximum voting value, including: performing a voting value comparison based on the node voting value corresponding to the latest version node to obtain a maximum voting value, and determining a first extreme standby node corresponding to the maximum voting value; A master node determination module is used to determine a target master node from a plurality of database nodes according to the node voting information.

7. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the database cluster master node determination method according to any one of claims 1 to 5 when executing the computer program.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for determining the master node of a database cluster according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Cluster-based city-level disaster recovery method and device, electronic equipment and medium

    CN113626252A

  • Database cluster split-brain prevention method and device, electronic equipment and storage medium

    CN117992501A