Database cluster master node determination method and device, electronic equipment and storage medium
By setting up the main node information storage area in the shared storage space of the database cluster, performing cluster node voting processing, and determining the target master node, solving the multi-master node problem caused by the backup node being promoted to the main node at the same time when the master node fails, and realizing the database High availability and stability of clusters.
Patent Information
- Application Number
- CN202411311779.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-09-20
AI Technical Summary
In a database cluster, when the primary node fails, the standby node may be promoted to the primary node at the same time, resulting in multiple primary nodes, causing confusion in data writing.
By setting up a primary node information storage area in the shared storage space, obtaining the primary node information, determining the primary node status, responding to the invalid state, voting processing of cluster nodes, and determining the target primary node.
Ensure that there is always only one valid master node in the database cluster, avoid data writing confusion, and improve the high availability and stability of the database cluster.
Smart Images

Figure CN119402333A_ABST
Abstract
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 the 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 file.
[0003] Database clusters usually adopt the master-slave mode, where the master node is responsible for processing all data write and update requests, and the standby node is responsible for processing data query and read requests. When the master node in the cluster fails, the standby node in the cluster will be promoted to the master node and continue to provide normal data read and write services to the upper-layer applications to ensure the high availability of the database cluster.
[0004] However, in some cases, when the master node fails, the backup nodes may all be promoted to master nodes in the same period of time, resulting in multiple master nodes in the cluster, which leads to confusion in data writing. Therefore, how to determine the master node of the database cluster has become a technical problem that needs to be solved urgently. 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-mentioned purpose, 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, wherein 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, and 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:
[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 processing 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 a time interval 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 of the database nodes is provided with a voting information storage area, and the cluster node voting process is performed on each of the cluster standby nodes to obtain corresponding node voting information, including:
[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 value standby node corresponding to the maximum voting value;
[0019] Obtain 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 also includes voting version information, and 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, it also includes:
[0022] Based on the voting version information of each of the cluster standby nodes, the latest node screening process is performed 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 according to 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] Based on the master node version information and time comparison information between the latest time data and the previous operation time data, obtaining the master node activity status of the cluster master node;
[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 proposes a database cluster master node determination device, the device comprising:
[0034] An information acquisition module, used to acquire the master node information through the master node information storage area;
[0035] A status determination module, used to determine the master node status of the cluster master node based on the master node information;
[0036] 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;
[0037] The master node determination module is used to determine a target master node from the plurality of 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 the processor implements the method for determining the master node of the database cluster described in the first aspect when executing the computer program.
[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, 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 only master node of the database cluster. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a flowchart of a method for determining a master node of a database cluster provided in an embodiment of the present application;
[0042] Figure 2 yes Figure 1 Flow chart of step S102 in FIG.
[0043] Figure 3 yes Figure 1 Flow chart of step S103 in FIG.
[0044] Figure 4 yes Figure 3 The flowchart before step S302 and step S302 in FIG.
[0045] Figure 5 yes Figure 1 Flow chart of step S104 in FIG.
[0046] Figure 6 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 It is a structural diagram of a database cluster master node determination device provided in an embodiment of the present application;
[0048] Figure 8 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0050] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0052] Traditional databases usually integrate data computing and storage in one physical space node. If the database is deployed in a cluster, all nodes in the cluster will store a copy of their own data, and data will be stored repeatedly, resulting in a waste of storage space. In order to solve this problem, related technologies have begun to develop shared storage database clusters. This architecture allows multiple database nodes to share a shared storage space, so that each node in the cluster can access the same database file, thereby reducing the cost of storage expansion and improving the availability of the database system.
[0053] Database clusters usually adopt the master-slave mode, where the master node is responsible for processing all data write and update requests, and the standby node is responsible for processing data query and read requests. When the master node in the cluster fails, the standby node in the cluster will be promoted to the master node and continue to provide normal data read and write services to the upper-layer applications to ensure the high availability of the database cluster.
[0054] However, in some cases, when the master node fails, the backup nodes may all be promoted to master nodes in the same period of time, resulting in multiple master nodes in the cluster, which leads to confusion in data writing. Therefore, how to determine the master node of the database cluster has become a technical problem that needs to be solved urgently.
[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 a 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 an 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 an 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, etc. 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, etc. 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 through 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 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 processing 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 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 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 only 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 set in the shared storage space formed by the database cluster to store the master node information of the cluster master node. Therefore, 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 set in size according to the total number of database nodes, and records the timestamp and verification information of the cluster master node performing the update operation.
[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 according to the master node identity information to obtain the master node query information;
[0069] Step S202, determining the master node status based on the master node query information.
[0070] In step S201 of some embodiments, the cluster master node is queried from multiple database nodes according to the master node identity information to obtain the master node query information. The database node information currently designated as the master node is obtained by querying the database cluster management service or configuration database. This may include identity information such as the cluster master node ID, IP address, port number, etc.
[0071] In step S202 of some embodiments, by querying the cluster master node, the master node query information is obtained, and the cluster master node's response time, heartbeat signal, error log and other indicators are analyzed to evaluate its operating status. It is checked whether the cluster master node 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, and the operation time data 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: based on the operation time data and a preset data update threshold time, the update operation of the cluster master node is detected at a time interval to determine the master node status.
[0074] When the cluster master node performs a write operation, a specific timestamp field, namely the operation time data, will be left in the master node information storage area. 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, it is considered that the cluster master node may be invalid. Technical personnel in this field can reasonably set this data update threshold time. This data update threshold time should be set according to the business needs and performance indicators of the cluster to ensure that normal operation delays can be tolerated and potential failures can be responded to in a timely manner. If it is detected that the master node has not performed any update operation within the normal operation 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 standby node 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;
[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: compare the node voting value of the first extreme value standby node with the node voting value of the second extreme value standby node to obtain the node voting information of each cluster standby node.
[0081] In step S301 of some embodiments, each cluster standby node generates a node voting value based on its own information, and the node voting value will be used in the subsequent comparison and election process. Each cluster standby 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 non-repetitive 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] Among them, 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 according to 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, simultaneous writing will not occur 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 value standby node is obtained, wherein the second extreme value 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, so the initial cluster node voting process will be performed, and at this time, the second extreme value standby node cannot be obtained. Therefore, in step S304, only the node voting value of the first extreme value standby node is valid, and the node voting value of the second extreme value 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 performed, the cluster master node can be obtained, but due to some failures or network problems, the cluster master node is invalid or lost, and the cluster node voting process will be performed again to obtain a new target master node. At this time, the valid second extreme value backup node can be obtained, and the corresponding valid node voting value can also be obtained.
[0090] In some embodiments, the selected first extreme value standby node will be marked in the corresponding voting information storage area, which can be recorded as an extreme value node mark, and the corresponding node voting value will be stored. In this way, the second extreme value standby node can be better determined when the cluster node voting process is performed later. When it is not the first cluster node voting process, it can be detected whether there is a corresponding extreme value node mark in other cluster standby nodes, and the corresponding node voting value can be obtained.
[0091] In step S304 of some embodiments, based on comparing the node voting value of the first extreme standby node with the node voting value of the second extreme standby node, node voting information for determining the target master node is obtained according to the comparison result. The target master node represents the database node that is about to become the cluster master node.
[0092] Through steps S301 to S304, by setting up a special 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, since the database nodes generate and write node voting values in their own specially set voting information storage areas when performing cluster node voting, no data will be written to the shared storage space. During the whole process, the writing of 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, and before step S302, it may include but is 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, compare the voting values based on the node voting values corresponding to the latest version node to obtain the maximum voting value, and determine the first extreme value standby node corresponding to the maximum voting value.
[0097] In step S401 of some embodiments, each cluster standby node records its own voting version information in the voting information storage area. The voting version information is usually an increasing number, which increases each time the node voting value is updated. The voting version information of each cluster standby node is synchronized and compared. The voting version information is stored in the voting information storage area to ensure that all cluster standby nodes can access the voting version information of other cluster standby nodes for comparison.
[0098] The latest version of the node is obtained by screening all the cluster standby nodes for the latest nodes. It should be noted that due to partitions in the database cluster or network delays, multiple node voting value updates may occur in a short period of time. In order to avoid the node voting values of different cluster nodes being read due to network delays when each cluster standby node performs cluster node voting, it is necessary to use voting version information to synchronize node voting values.
[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] Through step S401 to step S402, by introducing voting version information, the election process between cluster standby nodes can be managed more effectively, ensuring that the selected first extreme standby node not only has the highest node voting value, but also its voting information is the latest. This increases the reliability and accuracy of the election process and helps 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 failures. 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 also includes master node version information. Step S104 may include but is not limited to steps S501 to S503:
[0104] Step S501, obtaining 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, determining 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 reflects 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 carry 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, and 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 been selected yet 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] However, there is another possibility that 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 by 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 latest time data and the operation time data updated 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, the master node version information whose operation time data is different from the latest time data can be obtained, thereby determining that the target master node has been updated, and there is no need to determine a new target master node. 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 obtained by obtaining the latest time data and master node version information, thereby determining whether the database cluster has obtained the target master node. If the cluster master node is already active, it means that part of the database cluster has 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 failures, establishes multiple different target master nodes, avoids repeated updates of the target master node, and realizes accurate management of the cluster master node.
[0114] See also Figure 6 In some embodiments, when a network partition occurs in a database cluster, the database cluster will be 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, by performing cluster node voting processing on each cluster standby node in the multi-node partition, corresponding node voting information is obtained, and the target master node is determined from the database nodes in the multi-node partition according to the node voting information.
[0118] In step S601 of some embodiments, the multi-node partition represents a partition that includes more than half of the database cluster. The master node partition information of the cluster master node is determined according to the master node information, and the master node identity information in the master node information can be queried from the database cluster 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 few-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. It should be noted that each time the 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 to avoid 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, and 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 in a multi-node partition and perform related data update operations. Therefore, in order to maintain the high availability of the database cluster, maintain the continuity and good experience of the database cluster service, the cluster master node is kept in the multi-node partition as much as possible. When 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 a shared storage space jointly constituted by a 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 embodiment of the present application further 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 acquire the master node information through the master node information storage area;
[0125] A status determination module, 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 to 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 the node voting information.
[0128] The specific implementation of the database cluster master node determination device is basically the same as the specific implementation of the above-mentioned database cluster master node determination method, and will not be repeated here.
[0129] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above database cluster master node determination method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0130] See also Figure 8 , Figure 8 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0131] The processor 801 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used 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 solution provided in the embodiment of this specification is implemented by 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 embodiment of this application;
[0133] Input / output interface 803, used to implement information input and output;
[0134] The communication interface 804 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WI FI, Bluetooth, etc.);
[0135] A bus 805 that transmits information between the various components of the device (e.g., the processor 801, the memory 802, the input / output interface 803, and the 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, the above-mentioned method for determining the master node of the database cluster is implemented.
[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 disposed 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 the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present 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 the present application are also applicable to similar technical problems.
[0141] Those skilled in the art will appreciate 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, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0143] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination 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 sequence. 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 of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising 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 the present 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 objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single 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 the present 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 only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, 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 separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0148] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of 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 to enable 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 (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as 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 the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights 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, 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; 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, performing cluster node voting processing on each of the cluster standby nodes to obtain corresponding node voting information; 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 also 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 a time interval 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, characterized in that: Each of the database nodes is provided with a voting information storage area, and the cluster node voting process 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; Obtain 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; 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.
5. The method according to claim 4, characterized in that The voting information storage area also includes voting version information. 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, it also includes: Based on the voting version information of each of the cluster standby nodes, the latest node screening process is performed on the cluster standby nodes to obtain the latest version nodes; 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: 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.
6. The method according to claim 5, characterized in that 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 a 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; Based on the master node version information and time comparison information between the latest time data and the previous operation time data, obtaining the master node activity status of the cluster master node; A target master node is determined based on the master node activity status and the node voting information.
7. The method according to claim 6, 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.
8. A database cluster master node determination device, characterized in that: The device comprises: An information acquisition module, used to acquire the master node information through the master node information storage area; A status determination module, used 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; The master node determination module is used to determine a target master node from the plurality of database nodes according to the node voting information.
9. 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 method for determining the master node of a database cluster as described in any one of claims 1 to 7 when executing the computer program.
10. 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 7 is implemented.
Citation Information
Patent Citations
Cluster-based city-level disaster recovery method and device, electronic equipment and medium
CN113626252A
Node task scheduling method and device, computer equipment and storage medium
CN117453357A
Database cluster split-brain prevention method and device, electronic equipment and storage medium
CN117992501A
Cluster election method and device, equipment and medium
CN118200328A